Class: CommandUnion
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- CommandUnion
- Defined in:
- lib/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 |
# File 'lib/schema.rb', line 1742 def self.from_dynamic!(d) begin value = CommandStep.from_dynamic!(d) return new(command_step: value, string_array: nil, string: nil) if schema[:command_step].right.valid? value rescue StandardError end return new(string: d, string_array: nil, command_step: nil) if schema[:string].right.valid? d return new(string_array: d, command_step: nil, string: nil) if schema[:string_array].right.valid? d raise "Invalid union" end |
.from_json!(json) ⇒ Object
1754 1755 1756 |
# File 'lib/schema.rb', line 1754 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
1758 1759 1760 1761 1762 1763 1764 1765 1766 |
# File 'lib/schema.rb', line 1758 def to_dynamic if !command_step.nil? command_step.to_dynamic elsif !string.nil? string elsif !string_array.nil? string_array end end |
#to_json(options = nil) ⇒ Object
1768 1769 1770 |
# File 'lib/schema.rb', line 1768 def to_json( = nil) JSON.generate(to_dynamic, ) end |