Class: Input

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



1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
# File 'lib/schema.rb', line 1845

def self.from_dynamic!(d)
  begin
    value = InputStep.from_dynamic!(d)
    return new(input_step: value, string: nil) if schema[:input_step].right.valid? value
  rescue StandardError
  end
  return new(string: d, input_step: nil) if schema[:string].right.valid? d

  raise "Invalid union"
end

.from_json!(json) ⇒ Object



1856
1857
1858
# File 'lib/schema.rb', line 1856

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

Instance Method Details

#to_dynamicObject



1860
1861
1862
1863
1864
1865
1866
# File 'lib/schema.rb', line 1860

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

#to_json(options = nil) ⇒ Object



1868
1869
1870
# File 'lib/schema.rb', line 1868

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