Class: Slack4
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Slack4
- Defined in:
- lib/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/schema.rb', line 130 def self.from_dynamic!(d) begin value = Slack1.from_dynamic!(d) return new(slack1: value, string: nil) if schema[:slack1].right.valid? value rescue StandardError end return new(string: d, slack1: nil) if schema[:string].right.valid? d raise "Invalid union" end |
.from_json!(json) ⇒ Object
141 142 143 |
# File 'lib/schema.rb', line 141 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/schema.rb', line 145 def to_dynamic if !slack1.nil? slack1.to_dynamic elsif !string.nil? string end end |
#to_json(options = nil) ⇒ Object
153 154 155 |
# File 'lib/schema.rb', line 153 def to_json( = nil) JSON.generate(to_dynamic, ) end |