Class: Ricordami::ValueIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/ricordami/value_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fieldObject (readonly)

Returns the value of attribute field.



5
6
7
# File 'lib/ricordami/value_index.rb', line 5

def field
  @field
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/ricordami/value_index.rb', line 5

def model
  @model
end

#nameObject (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