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



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

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



2141
2142
2143
# File 'lib/schema.rb', line 2141

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

Instance Method Details

#to_dynamicObject



2145
2146
2147
2148
2149
2150
2151
# File 'lib/schema.rb', line 2145

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

#to_json(options = nil) ⇒ Object



2153
2154
2155
# File 'lib/schema.rb', line 2153

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