Module: Modis::Index::ClassMethods
- Defined in:
- lib/modis/index.rb
Instance Method Summary collapse
- #bootstrap_indexes(parent = nil) ⇒ Object
- #index(attribute) ⇒ Object
- #index_for(attribute, value) ⇒ Object
- #index_key(attribute, value) ⇒ Object
- #where(query) ⇒ Object
Instance Method Details
#bootstrap_indexes(parent = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/modis/index.rb', line 11 def bootstrap_indexes(parent = nil) class << self attr_accessor :indexed_attributes end self.indexed_attributes = parent ? parent.indexed_attributes.dup : [] end |
#index(attribute) ⇒ Object
19 20 21 22 23 |
# File 'lib/modis/index.rb', line 19 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) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/modis/index.rb', line 33 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) ⇒ Object
40 41 42 |
# File 'lib/modis/index.rb', line 40 def index_key(attribute, value) "#{absolute_namespace}:index:#{attribute}:#{value.inspect}" end |
#where(query) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/modis/index.rb', line 25 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 |