Class: Initializr::HashOf

Inherits:
Object
  • Object
show all
Defined in:
lib/initializr/hash_of.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ HashOf

Returns a new instance of HashOf.



4
5
6
# File 'lib/initializr/hash_of.rb', line 4

def initialize schema
  @schema = schema
end

Instance Method Details

#instantiate(obj) ⇒ Object



8
9
10
11
12
# File 'lib/initializr/hash_of.rb', line 8

def instantiate obj
  obj.keys.map do |key|
    Hash[key, @schema.instantiate(obj[key])]
  end.reduce({}, &:merge)
end