class ContentfulMiddleman::Context
Public Class Methods
new()
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 3 def initialize @variables = {} end
Public Instance Methods
ensure_primitive_data_types(value)
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 45 def ensure_primitive_data_types(value) case value when Context value.hashize when ::Array value.map {|element| ensure_primitive_data_types(element)} when ::Hash res = {} value.each do |k, v| res[ensure_primitive_data_types(k)] = ensure_primitive_data_types(v) end res else value end end
get(name)
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 22 def get(name) @variables.fetch(name.to_sym) end
has?(name)
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 26 def has?(name) @variables.key?(name) end
hashize()
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 38 def hashize variables = @variables.dup variables.update(variables) do |variable_name, variable_value| ensure_primitive_data_types(variable_value) end end
is_a?(klass)
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 30 def is_a?(klass) Context == klass end
method_missing(symbol, *args, &block)
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 7 def method_missing(symbol, *args, &block) if symbol =~ /\A.+=\z/ variable_name = symbol.to_s.gsub('=','') variable_value = args.first set variable_name, variable_value else get symbol end end
set(name, value)
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 18 def set(name, value) @variables[name.to_sym] = value end
to_yaml()
click to toggle source
# File lib/contentful_middleman/commands/context.rb, line 34 def to_yaml hashize.to_yaml end