Class: Cache

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

Overview

The paths for the caches to be used in the step

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



710
711
712
713
714
715
716
717
718
719
720
# File 'lib/schema.rb', line 710

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

  raise "Invalid union"
end

.from_json!(json) ⇒ Object



722
723
724
# File 'lib/schema.rb', line 722

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

Instance Method Details

#to_dynamicObject



726
727
728
729
730
731
732
733
734
# File 'lib/schema.rb', line 726

def to_dynamic
  if !cache_class.nil?
    cache_class.to_dynamic
  elsif !string.nil?
    string
  elsif !string_array.nil?
    string_array
  end
end

#to_json(options = nil) ⇒ Object



736
737
738
# File 'lib/schema.rb', line 736

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