Class: Redisabel::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/redisabel/search.rb

Instance Method Summary collapse

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

#keysObject



9
10
11
# File 'lib/redisabel/search.rb', line 9

def keys
  @keys ||= Database.db.keys(@pattern)
end

#objectsObject



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_typeObject



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