Class: Block

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



599
600
601
602
603
604
605
606
607
608
# File 'lib/schema.rb', line 599

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

  raise "Invalid union"
end

.from_json!(json) ⇒ Object



610
611
612
# File 'lib/schema.rb', line 610

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

Instance Method Details

#to_dynamicObject



614
615
616
617
618
619
620
# File 'lib/schema.rb', line 614

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

#to_json(options = nil) ⇒ Object



622
623
624
# File 'lib/schema.rb', line 622

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