Class: Transaction
- Inherits:
-
Object
- Object
- Transaction
- Defined in:
- lib/ObjectModel/Repository/Transaction.rb
Instance Attribute Summary collapse
-
#copies ⇒ Object
readonly
Returns the value of attribute copies.
-
#deleted_entities ⇒ Object
readonly
Returns the value of attribute deleted_entities.
-
#event_processor ⇒ Object
readonly
Returns the value of attribute event_processor.
-
#managed ⇒ Object
Returns the value of attribute managed.
-
#name ⇒ Object
Returns the value of attribute name.
-
#new_entities ⇒ Object
readonly
Returns the value of attribute new_entities.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#system_listener ⇒ Object
readonly
Returns the value of attribute system_listener.
Instance Method Summary collapse
- #changed?(entity_id) ⇒ Boolean
- #commit ⇒ Object
- #commited! ⇒ Object
- #commited? ⇒ Boolean
- #copy_get!(entity) ⇒ Object
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
- #resolve(entity_id) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 6 def initialize @name = "default" @copies = Hash.new{|hash, key| raise "Can't find Copy for '#{key}'entity_id!"} @new_entities = Hash.new{|hash, key| raise "Can't find New Entity for '#{key}' entity_id!"} @deleted_entities = Hash.new{|hash, key| raise "Can't find Deleted Entity for '#{key}' entity_id!"} @event_processor = EventProcessor.new(self) @system_listener = SystemListener.new(self) @commited = false @managed = false end |
Instance Attribute Details
#copies ⇒ Object (readonly)
Returns the value of attribute copies.
2 3 4 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2 def copies @copies end |
#deleted_entities ⇒ Object (readonly)
Returns the value of attribute deleted_entities.
2 3 4 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2 def deleted_entities @deleted_entities end |
#event_processor ⇒ Object (readonly)
Returns the value of attribute event_processor.
2 3 4 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2 def event_processor @event_processor end |
#managed ⇒ Object
Returns the value of attribute managed.
4 5 6 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 4 def managed @managed end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2 def name @name end |
#new_entities ⇒ Object (readonly)
Returns the value of attribute new_entities.
2 3 4 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2 def new_entities @new_entities end |
#repository ⇒ Object
Returns the value of attribute repository.
2 3 4 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2 def repository @repository end |
#system_listener ⇒ Object (readonly)
Returns the value of attribute system_listener.
2 3 4 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2 def system_listener @system_listener end |
Instance Method Details
#changed?(entity_id) ⇒ Boolean
47 48 49 50 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 47 def changed? entity_id entity_id.should! :be_a, String @copies.include?(entity_id) || @new_entities.include?(entity_id) end |
#commit ⇒ Object
43 44 45 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 43 def commit @repository.commit self end |
#commited! ⇒ Object
35 36 37 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 35 def commited! @commited = true end |
#commited? ⇒ Boolean
39 40 41 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 39 def commited? @commited end |
#copy_get!(entity) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 17 def copy_get! entity unless @copies.include? entity.entity_id copy = AnEntity::EntityType.create_copy entity @copies[entity.entity_id] = copy end @copies[entity.entity_id] end |
#resolve(entity_id) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 25 def resolve entity_id if @new_entities.include? entity_id @new_entities[entity_id] elsif @deleted_entities.include? entity_id @deleted_entities[entity_id] else @repository.by_id(entity_id) end end |
#to_s ⇒ Object Also known as: inspect
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ObjectModel/Repository/Transaction.rb', line 52 def to_s types = {:new => 0, :deleted => 0, :updated => 0, :moved => 0} methods = types.keys @copies.values.each do |c| methods.each do |m| types[m] += 1 if c.send :"#{m}?" end end return "#<Transaction: #{@name}#{commited? ? ", commited" : ""}, #{types.inspect}>" end |