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
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 |
# File 'lib/schema.rb', line 1236 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
1250 1251 1252 |
# File 'lib/schema.rb', line 1250 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
1254 1255 1256 1257 1258 1259 1260 |
# File 'lib/schema.rb', line 1254 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
1262 1263 1264 |
# File 'lib/schema.rb', line 1262 def to_json( = nil) JSON.generate(to_dynamic, ) end |