<commit_before># 
# @author - <NAME> (<EMAIL>)
#
# automatically maps basic properties, basic references, and basic collections
# when they are similarly named
#
class AutoMapper

  constructor: (@entityClass, @referenceBuilder=null)->

  canHandle: (entityClass)-> entityClass is @entityClass.name

  handle: (config)-> 
    entity = map.call @, config
    @buildEntity?(config, entity)
    @referenceBuilder.hydrateReferencesFor entity
    entity

  # PRIVATE

  map = (config)->
    entity = new @entityClass(config.id)
    for prop, value of config
      if hasProperty entity, prop
        if isReferenceProperty value
          @referenceBuilder.createReference(entity, prop, value.class, value.id)
        else if isReferenceCollectionProperty value
          refIds = if 'id' of value then value.id else value.ids
          @referenceBuilder.createReferenceCollection(entity, prop, value.class, refIds)
        else
          entity[prop] = value
    entity

  hasProperty = (entity, prop)-> prop of entity and not (entity[prop] instanceof Function)

  isReferenceProperty = (value)-> value instanceof Object and 'class' of value and 'id' of value and not (value.id instanceof Array)

  isReferenceCollectionProperty = (value)-> value instanceof Object and 'class' of value and ('ids' of value or ('id' of value and value.id instanceof Array))

return AutoMapper<commit_msg>brought EntityConstructorMap into AutoMapper for canHandle matching<commit_after>EntityConstructorMap = require 'scribe/repositories/entity_constructor_map'

# 
# @author - <NAME> (<EMAIL>)
#
# automatically maps basic properties, basic references, and basic collections
# when they are similarly named
#
class AutoMapper

  constructor: (@entityClass, @referenceBuilder=null)->

  canHandle: (entityClass)-> EntityConstructorMap.match(entityClass, @entityClass)

  handle: (config)-> 
    entity = map.call @, config
    @buildEntity?(config, entity)
    @referenceBuilder.hydrateReferencesFor entity
    entity

  # PRIVATE

  map = (config)->
    entity = new @entityClass(config.id)
    for prop, value of config
      if hasProperty entity, prop
        if isReferenceProperty value
          @referenceBuilder.createReference(entity, prop, value.class, value.id)
        else if isReferenceCollectionProperty value
          refIds = if 'id' of value then value.id else value.ids
          @referenceBuilder.createReferenceCollection(entity, prop, value.class, refIds)
        else
          entity[prop] = value
    entity

  hasProperty = (entity, prop)-> prop of entity and not (entity[prop] instanceof Function)

  isReferenceProperty = (value)-> value instanceof Object and 'class' of value and 'id' of value and not (value.id instanceof Array)

  isReferenceCollectionProperty = (value)-> value instanceof Object and 'class' of value and ('ids' of value or ('id' of value and value.id instanceof Array))

return AutoMapper
{'fraction_non_alphanumeric': 0.08984910836762688, 'fraction_numerical': 0.0, 'mean_word_length': 3.853577371048253, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1213440', 'n_tokens_mistral': 769, 'n_tokens_neox': 743, 'n_words': 272}