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
13 14 15 16 17 18 19 |
# 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) ⇒ Object
21 22 23 24 25 26 |
# 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) ⇒ Object
38 39 40 41 42 43 |
# 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) ⇒ Object
45 46 47 |
# File 'lib/modis/index.rb', line 45 def index_key(attribute, value) "#{absolute_namespace}:index:#{attribute}:#{value.inspect}" end |
#where(query) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# 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 |