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



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

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



1502
1503
1504
# File 'lib/schema.rb', line 1502

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

Instance Method Details

#to_dynamicObject



1506
1507
1508
1509
1510
1511
1512
# File 'lib/schema.rb', line 1506

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

#to_json(options = nil) ⇒ Object



1514
1515
1516
# File 'lib/schema.rb', line 1514

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