Module: Modis::Index::ClassMethods
- Defined in:
- lib/modis/index.rb
Instance Method Summary collapse
- #bootstrap_indexes ⇒ Object
- #index(attribute) ⇒ Object
- #index_for(attribute, value) ⇒ Object
- #index_key(attribute, value) ⇒ Object
- #where(query) ⇒ Object
Instance Method Details
#bootstrap_indexes ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/modis/index.rb', line 14 def bootstrap_indexes class << self attr_accessor :indexed_attributes end self.indexed_attributes = [] end |
#index(attribute) ⇒ Object
22 23 24 25 26 |
# File 'lib/modis/index.rb', line 22 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
35 36 37 38 39 40 |
# File 'lib/modis/index.rb', line 35 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
42 43 44 |
# File 'lib/modis/index.rb', line 42 def index_key(attribute, value) "#{absolute_namespace}:index:#{attribute}:#{value.inspect}" end |
#where(query) ⇒ Object
28 29 30 31 32 33 |
# 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 index = index_for(attribute, value) index.map { |id| find(id) } end |