Module: Roby::Transaction::PlanObjectProxy
- Defined in:
- lib/roby/transaction/plan_object_proxy.rb
Instance Method Summary collapse
-
#commit_transaction ⇒ Object
Commits the modifications of this proxy.
- #initialize_replacement(object, &block) ⇒ Object
-
#partition_new_old_relations(enum, include_proxies: true) ⇒ Object
Uses the
enum
method on this proxy and on the proxied object to get a set of objects related to this one in both the plan and the transaction. - #setup_proxy(object, plan) ⇒ Object
Instance Method Details
#commit_transaction ⇒ Object
Commits the modifications of this proxy. It copies the relations of the proxy on the proxied object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/roby/transaction/plan_object_proxy.rb', line 59 def commit_transaction # The relation graph handling is a bit tricky. We resolve the graphs # exclusively using self (NOT other) because if 'other' was a new # task, it has been already moved to the new plan (and its relation # graph resolution is using the new plan's new graphs already) super if @executable != __getobj__.instance_variable_get(:@executable) __getobj__.executable = @executable end finalization_handlers.each do |handler| __getobj__.when_finalized(handler., &handler.block) end end |
#initialize_replacement(object, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/roby/transaction/plan_object_proxy.rb', line 76 def initialize_replacement(object, &block) # Apply recursively all finalization handlers of this (proxied) # object to the object event # # We have to look at all levels as, in transactions, the "handlers" # set only contains new handlers real_object = self while real_object.transaction_proxy? real_object = real_object.__getobj__ real_object.finalization_handlers.each do |h| if h.copy_on_replace? object ||= yield object.when_finalized(h., &h.block) end end end if object super(object) else super(nil, &block) end end |
#partition_new_old_relations(enum, include_proxies: true) ⇒ Object
Uses the enum
method on this proxy and on the proxied object to get a set of objects related to this one in both the plan and the transaction.
The block is then given a plan_object => transaction_object hash, the relation which is being considered, the set of new relations (the relations that are in the transaction but not in the plan) and the set of deleted relation (relations that are in the plan but not in the transaction)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/roby/transaction/plan_object_proxy.rb', line 22 def partition_new_old_relations(enum, include_proxies: true) trsc_objects = {} each_relation do |rel| trsc_others = Set.new send(enum, rel) do |obj| plan_object = if obj.transaction_proxy? next unless include_proxies obj.__getobj__ else obj end trsc_objects[plan_object] = obj trsc_others << plan_object end plan_others = Set.new if include_proxies __getobj__.send(enum, rel) do |child| if plan[child, create: false] plan_others << child end end end new = (trsc_others - plan_others) existing = (trsc_others - new) del = (plan_others - trsc_others) yield(trsc_objects, rel, new, del, existing) end end |
#setup_proxy(object, plan) ⇒ Object
8 9 10 11 |
# File 'lib/roby/transaction/plan_object_proxy.rb', line 8 def setup_proxy(object, plan) super(object, plan) @finalization_handlers.clear end |