Class: Clickwrap::Retention::Applier
- Inherits:
-
Object
- Object
- Clickwrap::Retention::Applier
- Defined in:
- lib/clickwrap/retention/applier.rb
Overview
Applies a reviewed disposition plan.
result = Clickwrap::Retention::Applier.new(plan, applied_by: current_operator).call
result.counts # => {"applied" => 812, "skipped_held" => 4, ...}
The plan said what would happen. This re-asks every question before it does anything, because between the review and the run someone may have placed a legal hold, changed a retention class, released a hold, deleted a field by hand, or applied the plan already. When an item's answer has changed, that item stops and is reported — the run never deletes a broader set than the person who reviewed it agreed to, and never quietly deletes a narrower one either.
Each item is its own transaction: the deletion and the event that documents it commit together, and a failure on item 900 does not undo the 899 dispositions that already succeeded and were already recorded.
Defined Under Namespace
Instance Attribute Summary collapse
-
#applied_by ⇒ Object
readonly
Returns the value of attribute applied_by.
-
#at ⇒ Object
readonly
Returns the value of attribute at.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(plan, applied_by:, recover_application_if_stale_for: nil, because_recovery_is_needed: nil) ⇒ Applier
constructor
A new instance of Applier.
Constructor Details
#initialize(plan, applied_by:, recover_application_if_stale_for: nil, because_recovery_is_needed: nil) ⇒ Applier
Returns a new instance of Applier.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/clickwrap/retention/applier.rb', line 64 def initialize(plan, applied_by:, recover_application_if_stale_for: nil, because_recovery_is_needed: nil) @plan = plan @applied_by = applied_by @recover_application_if_stale_for = recover_application_if_stale_for @because_recovery_is_needed = because_recovery_is_needed @at = Clickwrap.now @applied = [] @skipped_held = [] @skipped_changed = [] @errors = [] end |
Instance Attribute Details
#applied_by ⇒ Object (readonly)
Returns the value of attribute applied_by.
77 78 79 |
# File 'lib/clickwrap/retention/applier.rb', line 77 def applied_by @applied_by end |
#at ⇒ Object (readonly)
Returns the value of attribute at.
77 78 79 |
# File 'lib/clickwrap/retention/applier.rb', line 77 def at @at end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
77 78 79 |
# File 'lib/clickwrap/retention/applier.rb', line 77 def plan @plan end |
Instance Method Details
#call ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/clickwrap/retention/applier.rb', line 79 def call # First, before anything is read or deleted: is this plan still one # somebody may act on? An expired, superseded, or already-applied plan # names a set that nobody currently agrees to. plan.claim_for_application!( by_reference: reference_for(applied_by), recover_if_stale_after: @recover_application_if_stale_for, because_recovery_is_needed: @because_recovery_is_needed ) plan_items.each { |item| apply_item(item) } # The plan is single-use whether or not every item succeeded. A plan # that could be run twice would be a plan whose second run nobody # reviewed; the operator re-plans instead, and the fresh plan shows what # is still outstanding. result = Result.new(applied: @applied, skipped_held: @skipped_held, skipped_changed: @skipped_changed, errors: @errors) plan.finish_application!(outcome_summary: result.to_h, had_errors: @errors.any?) result end |