Class: WipeOut::Execution::ExecutePlan
- Inherits:
-
Object
- Object
- WipeOut::Execution::ExecutePlan
- Extended by:
- Forwardable
- Defined in:
- lib/wipe_out/execution/execute_plan.rb
Instance Method Summary collapse
- #call ⇒ Object
- #collection?(record, relation_name) ⇒ Boolean
- #execute_on_attribute(attribute) ⇒ Object
- #execute_on_record(plan, record) ⇒ Object
- #process_relations ⇒ Object
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/wipe_out/execution/execute_plan.rb', line 11 def call execution.notify(:before_execution) process_relations plan.attributes.each(&method(:execute_on_attribute)) execution.run execution.notify(:after_execution) end |
#collection?(record, relation_name) ⇒ Boolean
48 49 50 |
# File 'lib/wipe_out/execution/execute_plan.rb', line 48 def collection?(record, relation_name) record.class.reflect_on_association(relation_name).collection? end |
#execute_on_attribute(attribute) ⇒ Object
36 37 38 39 40 |
# File 'lib/wipe_out/execution/execute_plan.rb', line 36 def execute_on_attribute(attribute) name, strategy = attribute value = strategy.call(record, name) record.send("#{name}=", value) end |
#execute_on_record(plan, record) ⇒ Object
42 43 44 45 46 |
# File 'lib/wipe_out/execution/execute_plan.rb', line 42 def execute_on_record(plan, record) execution_plan = plan.establish_execution_plan(record) ExecutePlan.call(execution.subexecution(execution_plan, record)) end |
#process_relations ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wipe_out/execution/execute_plan.rb', line 22 def process_relations plan.relations.each do |name, plan| relation = record.send(name) next unless relation.present? if collection?(record, name) relation.find_each { |record| execute_on_record(plan, record) } else execute_on_record(plan, relation) end end end |