Class: Redisabel::Search
- Inherits:
-
Object
- Object
- Redisabel::Search
- Defined in:
- lib/redisabel/search.rb
Instance Method Summary collapse
-
#initialize(pattern = '*', asave = false) ⇒ Search
constructor
A new instance of Search.
- #keys ⇒ Object
- #objects ⇒ Object
- #objects_by_type ⇒ Object
Constructor Details
#initialize(pattern = '*', asave = false) ⇒ Search
Returns a new instance of Search.
4 5 6 7 |
# File 'lib/redisabel/search.rb', line 4 def initialize(pattern='*', asave=false) @pattern = pattern @autosave = asave end |
Instance Method Details
#keys ⇒ Object
9 10 11 |
# File 'lib/redisabel/search.rb', line 9 def keys @keys ||= Database.db.keys(@pattern) end |
#objects ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/redisabel/search.rb', line 13 def objects self.keys @objects ||= @keys.map do |key| object_name, id = key.split(':') next object_name.camelize.constantize.new(@autosave, id, Transformations.transform(key)) end end |
#objects_by_type ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/redisabel/search.rb', line 22 def objects_by_type self.objects @objects_by_type ||= @objects.reduce({}) do |acc, obj| acc[obj.class] ||= [] acc[obj.class] << obj next acc end end |