Module: Schema::DataStructure::Build

Defined in:
lib/schema/data_structure.rb

Instance Method Summary collapse

Instance Method Details

#build(data = nil, strict = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/schema/data_structure.rb', line 22

def build(data=nil, strict=nil)
  data ||= {}
  strict ||= false

  new.tap do |instance|
    if not data.empty?
      instance.transform_read(data)
      set_attributes(instance, data, strict)
    end

    instance.configure_dependencies
  end
end

#set_attributes(instance, data, strict) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/schema/data_structure.rb', line 36

def set_attributes(instance, data, strict)
  begin
    SetAttributes.(instance, data, strict: strict)
  rescue SetAttributes::Assign::Error => e
    raise Schema::Error, e.message
  end
end