Class: Initializr::Schema
- Inherits:
-
Object
- Object
- Initializr::Schema
- Defined in:
- lib/initializr/schema.rb
Instance Method Summary collapse
-
#initialize(klass, schemas = {}) ⇒ Schema
constructor
A new instance of Schema.
- #instantiate(obj) ⇒ Object
Constructor Details
#initialize(klass, schemas = {}) ⇒ Schema
Returns a new instance of Schema.
4 5 6 7 |
# File 'lib/initializr/schema.rb', line 4 def initialize klass, schemas = {} @klass = klass @schemas = schemas end |
Instance Method Details
#instantiate(obj) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/initializr/schema.rb', line 9 def instantiate obj children = @schemas.keys.map do |key| value = @schemas[key].instantiate(obj[key]) Hash[key, value] end.reduce({}, &:merge) args = obj.merge(children) @klass.new args end |