Class: Sumac::RemoteReferences
Instance Method Summary collapse
- #commit_transaction ⇒ Object
- #destroy ⇒ Object
- #detach ⇒ Object
- #from_id(exposed_id) ⇒ Object
- #from_object(remote_object) ⇒ Object
-
#initialize(connection) ⇒ RemoteReferences
constructor
A new instance of RemoteReferences.
- #remove(reference) ⇒ Object
- #rollback_transaction ⇒ Object
- #start_transaction ⇒ Object
Constructor Details
#initialize(connection) ⇒ RemoteReferences
Returns a new instance of RemoteReferences.
4 5 6 7 8 9 |
# File 'lib/sumac/remote_references.rb', line 4 def initialize(connection) raise "argument 'connection' must be a Connection" unless connection.is_a?(Connection) @connection = connection @exposed_id_table = {} @transaction = [] end |
Instance Method Details
#commit_transaction ⇒ Object
40 41 42 |
# File 'lib/sumac/remote_references.rb', line 40 def commit_transaction @transaction = nil end |
#destroy ⇒ Object
15 16 17 |
# File 'lib/sumac/remote_references.rb', line 15 def destroy each { |reference| reference.destroy } end |
#detach ⇒ Object
11 12 13 |
# File 'lib/sumac/remote_references.rb', line 11 def detach each { |reference| reference.detach } end |
#from_id(exposed_id) ⇒ Object
19 20 21 22 |
# File 'lib/sumac/remote_references.rb', line 19 def from_id(exposed_id) raise unless IDAllocator.valid?(exposed_id) reference = find(exposed_id) || create(exposed_id) end |
#from_object(remote_object) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/sumac/remote_references.rb', line 24 def from_object(remote_object) raise unless remote_object.is_a?(RemoteObject) reference = remote_object.__remote_reference__ raise StaleObjectError unless reference.callable? reference end |
#remove(reference) ⇒ Object
31 32 33 |
# File 'lib/sumac/remote_references.rb', line 31 def remove(reference) @exposed_id_table.delete(reference.exposed_id) end |
#rollback_transaction ⇒ Object
35 36 37 38 |
# File 'lib/sumac/remote_references.rb', line 35 def rollback_transaction @transaction.each { |reference| reference.quiet_forget } @transaction = [] end |
#start_transaction ⇒ Object
44 45 46 |
# File 'lib/sumac/remote_references.rb', line 44 def start_transaction @transaction = [] end |