Class: AllowDependencyFailureUnion
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- AllowDependencyFailureUnion
- Defined in:
- lib/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
251 252 253 254 255 256 |
# File 'lib/schema.rb', line 251 def self.from_dynamic!(d) return new(bool: d, enum: nil) if schema[:bool].right.valid? d return new(enum: d, bool: nil) if schema[:enum].right.valid? d raise "Invalid union" end |
.from_json!(json) ⇒ Object
258 259 260 |
# File 'lib/schema.rb', line 258 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
262 263 264 265 266 267 268 |
# File 'lib/schema.rb', line 262 def to_dynamic if !bool.nil? bool elsif !enum.nil? enum end end |
#to_json(options = nil) ⇒ Object
270 271 272 |
# File 'lib/schema.rb', line 270 def to_json( = nil) JSON.generate(to_dynamic, ) end |