Class: Ricordami::ValueIndex
- Inherits:
-
Object
- Object
- Ricordami::ValueIndex
- Defined in:
- lib/ricordami/value_index.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(id, value) ⇒ Object
-
#initialize(model, field) ⇒ ValueIndex
constructor
A new instance of ValueIndex.
- #key_name_for_value(value) ⇒ Object
- #rem(id, value, return_command = false) ⇒ Object
Constructor Details
#initialize(model, field) ⇒ ValueIndex
Returns a new instance of ValueIndex.
7 8 9 10 11 |
# File 'lib/ricordami/value_index.rb', line 7 def initialize(model, field) @model = model @field = field.to_sym @name = "v_#{@field}".to_sym end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
5 6 7 |
# File 'lib/ricordami/value_index.rb', line 5 def field @field end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/ricordami/value_index.rb', line 5 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/ricordami/value_index.rb', line 5 def name @name end |
Instance Method Details
#add(id, value) ⇒ Object
17 18 19 |
# File 'lib/ricordami/value_index.rb', line 17 def add(id, value) @model.redis.sadd(key_name_for_value(value), id) end |
#key_name_for_value(value) ⇒ Object
13 14 15 |
# File 'lib/ricordami/value_index.rb', line 13 def key_name_for_value(value) KeyNamer.index(@model, :field => @field, :value => value) end |
#rem(id, value, return_command = false) ⇒ Object
21 22 23 24 |
# File 'lib/ricordami/value_index.rb', line 21 def rem(id, value, return_command = false) return [[:srem, [key_name_for_value(value), id]]] if return_command @model.redis.srem(key_name_for_value(value), id) end |