class Confidante::Converters::EvaluatingConverter

Public Class Methods

new() click to toggle source
# File lib/confidante/converters/evaluating_converter.rb, line 6
def initialize
  @sandbox = Shikashi::Sandbox.new
  @privileges = Shikashi::Privileges.new
end

Public Instance Methods

convert(thing) click to toggle source
# File lib/confidante/converters/evaluating_converter.rb, line 11
def convert(thing)
  case thing
  when Hash
    convert_hash(thing)
  when Array
    convert_array(thing)
  else
    convert_item(thing)
  end
end

Private Instance Methods

convert_array(thing) click to toggle source
# File lib/confidante/converters/evaluating_converter.rb, line 30
def convert_array(thing)
  thing.map { |v| convert(v) }
end
convert_hash(thing) click to toggle source
# File lib/confidante/converters/evaluating_converter.rb, line 24
def convert_hash(thing)
  {}.tap do |h|
    thing.each { |k, v| h[k.to_sym] = convert(v) }
  end
end
convert_item(thing) click to toggle source
# File lib/confidante/converters/evaluating_converter.rb, line 34
def convert_item(thing)
  if thing =~ /^[\[,{]/
    begin
      @sandbox.run(@privileges, thing)
    rescue Exception
      thing
    end
  else
    thing
  end
end