Class: Plugin

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/schema.rb

Overview

Array of plugins for this step

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
# File 'lib/schema.rb', line 1493

def self.from_dynamic!(d)
  begin
    value = Types::Hash[d].transform_values { |v| Types::Any[v] }
    return new(anything_map: value, string: nil) if schema[:anything_map].right.valid? value
  rescue StandardError
  end
  return new(string: d, anything_map: nil) if schema[:string].right.valid? d

  raise "Invalid union"
end

.from_json!(json) ⇒ Object



1504
1505
1506
# File 'lib/schema.rb', line 1504

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

Instance Method Details

#to_dynamicObject



1508
1509
1510
1511
1512
1513
1514
# File 'lib/schema.rb', line 1508

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

#to_json(options = nil) ⇒ Object



1516
1517
1518
# File 'lib/schema.rb', line 1516

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