class Riddler::Context

Attributes

variables[R]

Public Class Methods

new(input = nil) click to toggle source
# File lib/riddler/context.rb, line 6
def initialize input = nil
  input ||= {}
  @variables = {
    "ids" => {}
  }
  input.each do |key, value|
    next if value.nil?
    assign key, value
  end
end

Public Instance Methods

add_id(name, value) click to toggle source
# File lib/riddler/context.rb, line 30
def add_id name, value
  variables["ids"][name.to_s] = value
end
assign(name, value) click to toggle source
# File lib/riddler/context.rb, line 17
def assign name, value
  variables[name.to_s] = drop_for value
end
method_missing(method_name, *_args) click to toggle source
Calls superclass method
# File lib/riddler/context.rb, line 45
def method_missing method_name, *_args
  return super unless variables.key? method_name.to_s
  variable method_name
end
render(string) click to toggle source
# File lib/riddler/context.rb, line 25
def render string
  template = ::Liquid::Template.parse string
  template.render variables
end
to_hash() click to toggle source
# File lib/riddler/context.rb, line 38
def to_hash
  hash_array = variables.map do |key, value|
    [key, value.to_hash]
  end
  Hash[hash_array]
end
to_liquid() click to toggle source
# File lib/riddler/context.rb, line 34
def to_liquid
  Liquid::Context.new [variables]
end
variable(name) click to toggle source
# File lib/riddler/context.rb, line 21
def variable name
  variables[name.to_s]
end

Private Instance Methods

drop_for(data) click to toggle source
# File lib/riddler/context.rb, line 52
def drop_for data
  case data
  when ::Liquid::Drop
    data
  else
    ::Riddler::Drops::HashDrop.new data
  end
end