Class: Search
- Inherits:
-
Object
- Object
- Search
- Defined in:
- lib/redisant/search.rb
Instance Attribute Summary collapse
-
#class ⇒ Object
readonly
Returns the value of attribute class.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #add(record, value) ⇒ Object
-
#initialize(name, klass, options) ⇒ Search
constructor
A new instance of Search.
- #key(value) ⇒ Object
- #remove(record, value) ⇒ Object
- #update(record, prev_value, cur_value) ⇒ Object
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, @name = name.to_s @class = klass = end |
Instance Attribute Details
#class ⇒ Object (readonly)
Returns the value of attribute class.
3 4 5 |
# File 'lib/redisant/search.rb', line 3 def class @class end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/redisant/search.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/redisant/search.rb', line 3 def end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
3 4 5 |
# File 'lib/redisant/search.rb', line 3 def order @order end |
#type ⇒ Object (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 |