Module: Trufina::AllowCreationFromHash

Overview

Handle creating a HappyMapper object from array or hash (creating empty nodes as required).

Instance Method Summary collapse

Instance Method Details

#initialize(seed_data = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/elements.rb', line 9

def initialize(seed_data = {})
  create_nodes(seed_data)

  # Define attributes
  self.class.attributes.each do |attr|
    self.send("#{attr.method_name}=", nil) unless self.send(attr.method_name)
  end
  
  # Define elements
  self.class.attributes.each do |elem|
    self.send("#{elem.method_name}=", nil) unless self.send(elem.method_name)
  end
end