class Relix::Index
Attributes
model_name[R]
Public Class Methods
compact_kind()
click to toggle source
# File lib/relix/index.rb, line 7 def self.compact_kind @compact_kind ||= kind[0..0] end
kind()
click to toggle source
# File lib/relix/index.rb, line 3 def self.kind @kind ||= name.gsub(/(?:^.+::|Index$)/, '').gsub(/([a-z])([A-Z])/){"#{$1}_#{$2}"}.downcase end
new(set, base_name, accessors, options={})
click to toggle source
# File lib/relix/index.rb, line 31 def initialize(set, base_name, accessors, options={}) @set = set @base_name = base_name @model_name = @set.klass.name @accessors = Array(accessors).collect{|a| Accessor.new(a)} @attribute_immutable = options[:immutable_attribute] @conditional = options[:if] @options = options end
Public Instance Methods
attribute_immutable?()
click to toggle source
# File lib/relix/index.rb, line 93 def attribute_immutable? @attribute_immutable end
create_query_clause(redis)
click to toggle source
# File lib/relix/index.rb, line 89 def create_query_clause(redis) Query::Clause.new(redis, self) end
filter(r, pk, object, value)
click to toggle source
# File lib/relix/index.rb, line 77 def filter(r, pk, object, value) true end
index?(r, object, value)
click to toggle source
# File lib/relix/index.rb, line 81 def index?(r, object, value) (@conditional ? object.send(@conditional) : true) end
name()
click to toggle source
# File lib/relix/index.rb, line 41 def name @set.keyer.index(self, @base_name) end
normalize(value)
click to toggle source
# File lib/relix/index.rb, line 53 def normalize(value) value_hash = case value when Hash value.inject({}){|h, (k,v)| h[k.to_s] = v; h} else {@accessors.first.identifier => value} end @accessors.collect do |accessor| if value_hash.include?(accessor.identifier) value_hash[accessor.identifier].to_s else raise MissingIndexValueError, "Missing #{accessor.identifier} when looking up by #{name}" end end.join(":") end
query(r, value)
click to toggle source
# File lib/relix/index.rb, line 85 def query(r, value) nil end
read(object)
click to toggle source
# File lib/relix/index.rb, line 45 def read(object) @accessors.inject({}){|h,e| h[e.identifier] = e.read(object); h} end
read_normalized(object)
click to toggle source
# File lib/relix/index.rb, line 49 def read_normalized(object) normalize(read(object)) end
watch(*values)
click to toggle source
# File lib/relix/index.rb, line 69 def watch(*values) watch_keys(*values) unless attribute_immutable? end
watch_keys(*values)
click to toggle source
# File lib/relix/index.rb, line 73 def watch_keys(*values) nil end