Class: Zermelo::Associations::UniqueIndex
- Inherits:
-
Object
- Object
- Zermelo::Associations::UniqueIndex
- Defined in:
- lib/zermelo/associations/unique_index.rb
Instance Method Summary collapse
- #add_id(id, value) ⇒ Object
- #delete_id(id, value) ⇒ Object
-
#initialize(parent_klass, name) ⇒ UniqueIndex
constructor
A new instance of UniqueIndex.
- #key ⇒ Object
- #key_dump ⇒ Object
- #move_id(id, value_from, indexer_to, value_to) ⇒ Object
Constructor Details
#initialize(parent_klass, name) ⇒ UniqueIndex
Returns a new instance of UniqueIndex.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/zermelo/associations/unique_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/unique_index.rb', line 24 def add_id(id, value) @backend.add(key, @backend.index_keys(@attribute_type, value).join(':') => id) end |
#delete_id(id, value) ⇒ Object
20 21 22 |
# File 'lib/zermelo/associations/unique_index.rb', line 20 def delete_id(id, value) @backend.delete(key, @backend.index_keys(@attribute_type, value).join(':')) end |
#key ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/zermelo/associations/unique_index.rb', line 33 def key @indexer ||= Zermelo::Records::Key.new( :klass => @parent_klass, :name => "by_#{@attribute_name}", :type => :hash, :object => :index ) end |
#key_dump ⇒ Object
42 43 44 |
# File 'lib/zermelo/associations/unique_index.rb', line 42 def key_dump [@backend.key_to_backend_key(key), key] end |
#move_id(id, value_from, indexer_to, value_to) ⇒ Object
28 29 30 31 |
# File 'lib/zermelo/associations/unique_index.rb', line 28 def move_id(id, value_from, indexer_to, value_to) @backend.move(key, {@backend.index_keys(@attribute_type, value_from).join(':') => id}, indexer_to.key, {@backend.index_keys(@attribute_type, value_to).join(':') => id}) end |