class Elastics::Variables
Public Class Methods
new(*hashes)
click to toggle source
Calls superclass method
Elastics::Struct::Hash::new
# File lib/elastics/variables.rb, line 4 def initialize(*hashes) deep_merge! super(), *hashes end
Public Instance Methods
fetch_nested(key)
click to toggle source
allows to fetch values for tag names like 'a.3.c' fetching vars[3]
# File lib/elastics/variables.rb, line 45 def fetch_nested(key) unnest(key).inject(self, :fetch) rescue NoMethodError, KeyError # return the milliseconds for :now if it is not set explicitly return (Time.now.to_f * 1000).to_i if key == :now raise MissingVariableError, "the required #{key.inspect} variable is missing." end
fetch_value(key)
click to toggle source
returns Prunable::Value if the value is in VALUES (called from stringified)
# File lib/elastics/variables.rb, line 24 def fetch_value(key) val = fetch_nested(key) return val if self[:no_pruning].include?(key) Prunable::VALUES.include?(val) ? Prunable::Value : val end
finalize()
click to toggle source
# File lib/elastics/variables.rb, line 8 def finalize self[:index] = self[:index].uniq.join(',') if self[:index].is_a?(Array) self[:type] = self[:type].uniq.join(',') if self[:type].is_a?(Array) # so you can pass :fields => [:field_one, :field_two] self[:params!].each{|k,v| self[:params][k] = v.uniq.join(',') if v.is_a?(Array)} if self[:page] self[:page] = self[:page].to_i self[:page] = 1 unless self[:page] > 0 self[:params][:from] ||= ((self[:page] - 1) * (self[:params][:size] || 10)).ceil unless self[:page] == 1 else self[:page] = 1 end self end
store_nested(key, value)
click to toggle source
Private Instance Methods
unnest(key)
click to toggle source
# File lib/elastics/variables.rb, line 55 def unnest(key) key.to_s.split('.').map{|s| s =~ /^\d+$/ ? s.to_i : s.to_sym} end