Class: Search

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, klass, options) ⇒ Search

Returns a new instance of Search.



4
5
6
7
8
# File 'lib/redisant/search.rb', line 4

def initialize name, klass, options
  @name = name.to_s
  @class = klass
  @options = options
end

Instance Attribute Details

#classObject (readonly)

Returns the value of attribute class.



3
4
5
# File 'lib/redisant/search.rb', line 3

def class
  @class
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/redisant/search.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/redisant/search.rb', line 3

def options
  @options
end

#orderObject (readonly)

Returns the value of attribute order.



3
4
5
# File 'lib/redisant/search.rb', line 3

def order
  @order
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/redisant/search.rb', line 3

def type
  @type
end

Instance Method Details

#add(record, value) ⇒ Object



14
15
16
# File 'lib/redisant/search.rb', line 14

def add record, value
  $redis.sadd key(value), record.id.to_s
end

#key(value) ⇒ Object



10
11
12
# File 'lib/redisant/search.rb', line 10

def key value
  "#{@class.name.downcase}:search:#{@name}:#{value}"
end

#remove(record, value) ⇒ Object



25
26
27
# File 'lib/redisant/search.rb', line 25

def remove record, value
  $redis.srem key(value), record.id.to_s
end

#update(record, prev_value, cur_value) ⇒ Object



18
19
20
21
22
23
# File 'lib/redisant/search.rb', line 18

def update record, prev_value, cur_value
  if prev_value != cur_value
    remove record, prev_value
    add record, cur_value
  end
end