Class: Manager
- Inherits:
-
Object
- Object
- Manager
- Defined in:
- lib/ObjectModel/Indexes/Manager.rb
Instance Attribute Summary collapse
-
#indexes ⇒ Object
Returns the value of attribute indexes.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(index) ⇒ Object
- #build_indexes ⇒ Object
- #clear_indexes ⇒ Object
- #delete(index_name) ⇒ Object
- #get_index_without_transaction_check(name) ⇒ Object
-
#initialize(repository) ⇒ Manager
constructor
A new instance of Manager.
- #update(transaction) ⇒ Object
Constructor Details
#initialize(repository) ⇒ Manager
Returns a new instance of Manager.
4 5 6 7 8 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 4 def initialize repository @repository = repository @indexes = Hash.new{|hash, key| raise_without_self "No Index - '#{key}'!", ObjectModel} @not_initialized = Set.new end |
Instance Attribute Details
#indexes ⇒ Object
Returns the value of attribute indexes.
2 3 4 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 2 def indexes @indexes end |
Instance Method Details
#[](name) ⇒ Object
40 41 42 43 44 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 40 def [] name check_transaction @not_initialized.should! :be_empty return @indexes[name] end |
#add(index) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 10 def add index index.name.should! :be_a, Symbol @indexes[index.name] = index index.storage = @repository.indexes_storage index.repository = @repository builded = index.create_index @not_initialized << index unless builded end |
#build_indexes ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 57 def build_indexes check_transaction @not_initialized.every.create_index @repository.indexes_storage.transaction do @repository.each{|e| @not_initialized.every.add e} end @not_initialized.clear end |
#clear_indexes ⇒ Object
51 52 53 54 55 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 51 def clear_indexes check_transaction @indexes.values.every.delete_index @not_initialized.replace @indexes.values end |
#delete(index_name) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 19 def delete index_name index_name.should! :be_a, Symbol index = @indexes.delete index_name index.should_not! :be_nil index.delete_index @not_initialized.delete index end |
#get_index_without_transaction_check(name) ⇒ Object
46 47 48 49 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 46 def get_index_without_transaction_check name @not_initialized.should! :be_empty return @indexes[name] end |
#update(transaction) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ObjectModel/Indexes/Manager.rb', line 27 def update transaction Thread.current[:om_transaction].should_not! :be_nil @not_initialized.should! :be_empty @repository.indexes_storage.transaction do indexes = @indexes.values transaction.copies.each do |entity_id, c| e = transaction.resolve entity_id indexes.every.update e, c end end end |