Class: Zermelo::Associations::RangeIndex
- Inherits:
-
Object
- Object
- Zermelo::Associations::RangeIndex
- Defined in:
- lib/zermelo/associations/range_index.rb
Instance Method Summary collapse
- #add_id(id, value) ⇒ Object
- #delete_id(id, value) ⇒ Object
-
#initialize(parent_klass, name) ⇒ RangeIndex
constructor
A new instance of RangeIndex.
- #key ⇒ Object
- #move_id(id, value_from, indexer_to, value_to) ⇒ Object
Constructor Details
#initialize(parent_klass, name) ⇒ RangeIndex
Returns a new instance of RangeIndex.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/zermelo/associations/range_index.rb', line 9 def initialize(parent_klass, name) @parent_klass = parent_klass @attribute_name = name @backend = parent_klass.send(:backend) parent_klass.send(:with_index_data, name.to_sym) do |data| @attribute_type = data.type end end |
Instance Method Details
#add_id(id, value) ⇒ Object
24 25 26 |
# File 'lib/zermelo/associations/range_index.rb', line 24 def add_id(id, value) @backend.add(key, [@backend.safe_value(@attribute_type, value), id]) end |
#delete_id(id, value) ⇒ Object
20 21 22 |
# File 'lib/zermelo/associations/range_index.rb', line 20 def delete_id(id, value) @backend.delete(key, id) end |
#key ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/zermelo/associations/range_index.rb', line 33 def key @indexer ||= Zermelo::Records::Key.new( :klass => @parent_klass, :name => "by_#{@attribute_name}", :type => :sorted_set, :object => :index ) end |
#move_id(id, value_from, indexer_to, value_to) ⇒ Object
28 29 30 31 |
# File 'lib/zermelo/associations/range_index.rb', line 28 def move_id(id, value_from, indexer_to, value_to) @backend.move(key, [@backend.safe_value(@attribute_type, value_from), id], indexer_to.key, [@backend.safe_value(@attribute_type, value_to), id]) end |