Class: Setup
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Setup
- Defined in:
- lib/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 |
# File 'lib/schema.rb', line 1234 def self.from_dynamic!(d) begin value = d.map { |x| MatrixElement.from_dynamic!(x) } return new(union_array: value, union_array_map: nil) if schema[:union_array].right.valid? value rescue StandardError end begin value = Types::Hash[d].transform_values { |v| v.map { |x| MatrixElement.from_dynamic!(x) } } return new(union_array_map: value, union_array: nil) if schema[:union_array_map].right.valid? value rescue StandardError end raise "Invalid union" end |
.from_json!(json) ⇒ Object
1248 1249 1250 |
# File 'lib/schema.rb', line 1248 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
1252 1253 1254 1255 1256 1257 1258 |
# File 'lib/schema.rb', line 1252 def to_dynamic if !union_array.nil? union_array.map(&:to_dynamic) elsif !union_array_map.nil? union_array_map.transform_values { |v| v.map(&:to_dynamic) } end end |
#to_json(options = nil) ⇒ Object
1260 1261 1262 |
# File 'lib/schema.rb', line 1260 def to_json( = nil) JSON.generate(to_dynamic, ) end |