module Modis::Index::ClassMethods
Attributes
indexed_attributes[RW]
Public Instance Methods
bootstrap_indexes(parent = nil)
click to toggle source
# File lib/modis/index.rb, line 13 def bootstrap_indexes(parent = nil) class << self attr_accessor :indexed_attributes end self.indexed_attributes = parent ? parent.indexed_attributes.dup : [] end
index(attribute)
click to toggle source
# File lib/modis/index.rb, line 21 def index(attribute) attribute = attribute.to_s raise IndexError, "No such attribute '#{attribute}'" unless attributes.key?(attribute) indexed_attributes << attribute end
index_for(attribute, value)
click to toggle source
# File lib/modis/index.rb, line 38 def index_for(attribute, value) Modis.with_connection do |redis| key = index_key(attribute, value) redis.smembers(key).map(&:to_i) end end
index_key(attribute, value)
click to toggle source
# File lib/modis/index.rb, line 45 def index_key(attribute, value) "#{absolute_namespace}:index:#{attribute}:#{value.inspect}" end
where(query)
click to toggle source
# File lib/modis/index.rb, line 28 def where(query) raise IndexError, 'Queries using multiple indexes is not currently supported.' if query.keys.size > 1 attribute, value = query.first ids = index_for(attribute, value) return [] if ids.empty? find_all(ids) end