Class: Chronicle::Models::ModelFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/chronicle/models/model_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_id:, properties: []) ⇒ ModelFactory

Returns a new instance of ModelFactory.



6
7
8
9
# File 'lib/chronicle/models/model_factory.rb', line 6

def initialize(type_id:, properties: [])
  @type_id = type_id
  @properties = properties
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/chronicle/models/model_factory.rb', line 4

def id
  @id
end

Instance Method Details

#generateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chronicle/models/model_factory.rb', line 11

def generate
  attribute_info = @properties.map do |property|
    generate_attribute_info(property)
  end

  type_id = @type_id

  Class.new(Chronicle::Models::Base) do
    attribute_info.each do |a|
      attribute(a[:name], a[:type])
    end

    @type_id = type_id
  end
end