Class: Trigger

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



2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
# File 'lib/schema.rb', line 2132

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

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

.from_json!(json) ⇒ Object



2143
2144
2145
# File 'lib/schema.rb', line 2143

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

Instance Method Details

#to_dynamicObject



2147
2148
2149
2150
2151
2152
2153
# File 'lib/schema.rb', line 2147

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

#to_json(options = nil) ⇒ Object



2155
2156
2157
# File 'lib/schema.rb', line 2155

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