Class: ROM::Factory::Struct

Inherits:
Dry::Struct
  • Object
show all
Extended by:
Dry::Core::Cache
Defined in:
lib/rom/factory/struct.rb

Class Method Summary collapse

Class Method Details

.define(name, schema) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rom/factory/struct.rb', line 9

def self.define(name, schema)
  fetch_or_store(schema) do
    id = Dry::Core::Inflector.classify(Dry::Core::Inflector.singularize(name))

    Dry::Core::ClassBuilder.new(name: "ROM::Factory::Struct[#{id}]", parent: self).call do |klass|
      schema.each do |attr|
        klass.attribute attr.name, attr.type
      end
    end
  end
end