Class: NotifyElement

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



1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
# File 'lib/schema.rb', line 1458

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

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

.from_json!(json) ⇒ Object



1469
1470
1471
# File 'lib/schema.rb', line 1469

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

Instance Method Details

#to_dynamicObject



1473
1474
1475
1476
1477
1478
1479
# File 'lib/schema.rb', line 1473

def to_dynamic
  if !enum.nil?
    enum
  elsif !notify_class.nil?
    notify_class.to_dynamic
  end
end

#to_json(options = nil) ⇒ Object



1481
1482
1483
# File 'lib/schema.rb', line 1481

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