Class: Label

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
# File 'lib/schema.rb', line 2234

def self.from_dynamic!(d)
  return new(null: d, wait_step: nil, string: nil) if schema[:null].right.valid? d
  return new(string: d, wait_step: nil, null: nil) if schema[:string].right.valid? d

  begin
    value = WaitStep.from_dynamic!(d)
    return new(wait_step: value, null: nil, string: nil) if schema[:wait_step].right.valid? value
  rescue StandardError
  end
  raise "Invalid union"
end

.from_json!(json) ⇒ Object



2246
2247
2248
# File 'lib/schema.rb', line 2246

def self.from_json!(json)
  from_dynamic!(JSON.parse(json))
end

Instance Method Details

#to_dynamicObject



2250
2251
2252
2253
2254
2255
2256
# File 'lib/schema.rb', line 2250

def to_dynamic
  if !string.nil?
    string
  elsif !wait_step.nil?
    wait_step.to_dynamic
  end
end

#to_json(options = nil) ⇒ Object



2258
2259
2260
# File 'lib/schema.rb', line 2258

def to_json(options = nil)
  JSON.generate(to_dynamic, options)
end