Module: Hash19::Core::Initializer

Defined in:
lib/hash19/core.rb

Instance Method Summary collapse

Instance Method Details

#initialize(payload = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hash19/core.rb', line 13

def initialize(payload={})
  if payload.is_a? Array
    @hash19 = payload.map do |el|
      klass = resolve_class(self.class.contains_klass.to_s.camelize.singularize)
      klass.send(:new, el).to_h(true)
    end
  else
    hash = payload.with_indifferent_access
    @hash19 = hash.slice(*self.class.keys)
    resolve_aliases if self.class.aliases.present?
    resolve_transformers if self.class.transformers.present?
    resolve_has_one(hash) if self.class.one_assocs.present?
    resolve_has_many(hash) if self.class.many_assocs.present?
  end
  resolve_injections(@hash19) if self.class.injections.present?
end