Class: Agents
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Agents
- Defined in:
- lib/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/schema.rb', line 44 def self.from_dynamic!(d) begin value = Types::Hash[d].transform_values { |v| Types::Any[v] } return new(anything_map: value, string_array: nil) if schema[:anything_map].right.valid? value rescue StandardError end return new(string_array: d, anything_map: nil) if schema[:string_array].right.valid? d raise "Invalid union" end |
.from_json!(json) ⇒ Object
55 56 57 |
# File 'lib/schema.rb', line 55 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/schema.rb', line 59 def to_dynamic if !anything_map.nil? anything_map elsif !string_array.nil? string_array end end |
#to_json(options = nil) ⇒ Object
67 68 69 |
# File 'lib/schema.rb', line 67 def to_json( = nil) JSON.generate(to_dynamic, ) end |