Method: DataModel::Struct#initialize
- Defined in:
- lib/data_model/struct.rb
#initialize(data = {}, coerce: false, strict: true) ⇒ void
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/data_model/struct.rb', line 85 def initialize(data = {}, coerce: false, strict: true) @coerce = coerce @strict = strict @values = {} @errors = Error.new if data.nil? return end for k, v in data send("#{k}=", v) end for req in self.class.required_types for key in data.keys if key.to_s == req.to_s next end end raise "Missing required field #{req}" end end |