<commit_before>

Base  = require './base'
TYPES = require './types'

###*
Base factory class of DDD pattern.

create instance of model

the parent "Base" class just simply gives a @getFacade() method.

@class BaseFactory
@extends Base
@module base-domain
###
class BaseFactory extends Base

    ###*
    model name to handle

    @property modelName
    @static
    @protected
    @type String
    ###
    @modelName: null


    ###*
    key-value pair of prop name -> type info  when prop is model/models

    @property modelProperties
    @protected
    @type Object
    ###

    ###*
    constructor

    @constructor
    @param {Object} [options]
    @return
    ###
    constructor: (options)->
        @modelProperties = {}

        propertyInfo = @getModelClass().properties

        for prop, type of propertyInfo
            typeInfo = TYPES.info(type)
            if typeInfo.model
                @modelProperties[prop] = typeInfo



    ###*
    get model class this factory handles

    @method getModelClass
    @return {Class}
    ###
    getModelClass: ->
        modelName = @constructor.modelName
        @getFacade().getModel(modelName)


    ###*
    create empty model instance

    @method createEmptyModel
    @return {BaseModel}
    ###
    createEmptyModel: ->
        ModelClass = @getModelClass()
        model = new ModelClass()
        return @afterCreateModel model



    ###*
    create instance of model class by plain object

    for each prop, values are modified by @modifyValueByPropName()

    @method createFromObject
    @public
    @param {Object} obj
    @return {BaseModel} model
    ###
    createFromObject: (obj) ->

        obj = @beforeCreateFromObject obj

        if not obj? or typeof obj isnt 'object'
            return null


        model = @createEmptyModel()

        for own prop, value of obj

            if prop is 'id'
                model.id = @modifyIdValue value

            else
                model[prop] = @modifyValueByPropName(prop, value)

        return @afterCreateModel model


    ###*
    modify plain object before @createFromObject(obj)<commit_msg>afterCreateModel() should be run once in BaseFactory#createObjectModel()<commit_after>

Base  = require './base'
TYPES = require './types'

###*
Base factory class of DDD pattern.

create instance of model

the parent "Base" class just simply gives a @getFacade() method.

@class BaseFactory
@extends Base
@module base-domain
###
class BaseFactory extends Base

    ###*
    model name to handle

    @property modelName
    @static
    @protected
    @type String
    ###
    @modelName: null


    ###*
    key-value pair of prop name -> type info  when prop is model/models

    @property modelProperties
    @protected
    @type Object
    ###

    ###*
    constructor

    @constructor
    @param {Object} [options]
    @return
    ###
    constructor: (options)->
        @modelProperties = {}

        propertyInfo = @getModelClass().properties

        for prop, type of propertyInfo
            typeInfo = TYPES.info(type)
            if typeInfo.model
                @modelProperties[prop] = typeInfo



    ###*
    get model class this factory handles

    @method getModelClass
    @return {Class}
    ###
    getModelClass: ->
        modelName = @constructor.modelName
        @getFacade().getModel(modelName)


    ###*
    create empty model instance

    @method createEmptyModel
    @return {BaseModel}
    ###
    createEmptyModel: ->
        ModelClass = @getModelClass()
        model = new ModelClass()
        return @afterCreateModel model



    ###*
    create instance of model class by plain object

    for each prop, values are modified by @modifyValueByPropName()

    @method createFromObject
    @public
    @param {Object} obj
    @return {BaseModel} model
    ###
    createFromObject: (obj) ->

        obj = @beforeCreateFromObject obj

        if not obj? or typeof obj isnt 'object'
            return null


        ModelClass = @getModelClass()
        model = new ModelClass()

        for own prop, value of obj

            if prop is 'id'
                model.id = @modifyIdValue value

            else
                model[prop] = @modifyValueByPropName(prop, value)

        return @afterCreateModel model


    ###*
    modify plain object before @createFromObject(obj)
{'fraction_non_alphanumeric': 0.09145220588235294, 'fraction_numerical': 0.0, 'mean_word_length': 2.236431226765799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2105489', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1161, 'n_words': 378}