Class: WipeOut::Plans::Dsl
- Inherits:
-
Object
- Object
- WipeOut::Plans::Dsl
- Extended by:
- Forwardable
- Includes:
- WipeOut::Plugin::ClassMethods
- Defined in:
- lib/wipe_out/plans/dsl.rb
Overview
Provides DSL methods available during Plan building.
Instance Method Summary collapse
-
#configure {|plan.config| ... } ⇒ Config
See Config to check what options are available.
-
#ignore(*names) ⇒ nil
Sets given attribute(s) as ignored.
-
#ignore_all ⇒ Object
Ignores all attributes and relations during validation.
- #include_plan(built_plan) ⇒ Object
-
#include_plan!(other_plan) ⇒ nil
Combines plan with another one.
-
#on_execute {|WipeOut::Execution::Context| ... } ⇒ nil
Overwrites default
#save!
which is called on record after wipe out. -
#relation(name, plan = nil, plans: nil, &block) ⇒ nil
Configures plan for wiping out data in relation.
-
#wipe_out(*names, strategy: AttributeStrategies::Nullify, &block) ⇒ nil
Defines a strategy for removing data inside attribute(s).
Methods included from WipeOut::Plugin::ClassMethods
#after, #before, #callback, #callbacks
Instance Method Details
#configure {|plan.config| ... } ⇒ Config
add test for nested configurations inside plans
See Config to check what options are available.
110 111 112 113 114 |
# File 'lib/wipe_out/plans/dsl.rb', line 110 def configure yield plan.config plan.config end |
#ignore(*names) ⇒ nil
Sets given attribute(s) as ignored. Attributes must be ignored explicily otherwise errors will be raised during validation
90 91 92 93 94 |
# File 'lib/wipe_out/plans/dsl.rb', line 90 def ignore(*names) names.each do |name| plan.ignore(name) end end |
#ignore_all ⇒ Object
Ignores all attributes and relations during validation.
It should be used when you're using custom #on_execute
method that
for example destroys records and you don't care what attributes are there exactly
99 100 101 |
# File 'lib/wipe_out/plans/dsl.rb', line 99 def ignore_all plan.ignore(WipeOut::IGNORE_ALL) end |
#include_plan(built_plan) ⇒ Object
103 104 105 |
# File 'lib/wipe_out/plans/dsl.rb', line 103 def include_plan(built_plan) plan.include_plan(built_plan.plan) end |
#include_plan!(other_plan) ⇒ nil
Combines plan with another one. You can use it to create plans out of other plans via composition.
37 |
# File 'lib/wipe_out/plans/dsl.rb', line 37 def_delegators :@plan, :on_execute |
#on_execute {|WipeOut::Execution::Context| ... } ⇒ nil
Overwrites default #save!
which is called on record after wipe out.
You can use this to switch to #destroy!
or #delete!
if needed.
You can also configure this in Config
37 |
# File 'lib/wipe_out/plans/dsl.rb', line 37 def_delegators :@plan, :on_execute |
#relation(name, plan = nil, plans: nil, &block) ⇒ nil
Configures plan for wiping out data in relation. You must pass a block and use the same DSL to configure it.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/wipe_out/plans/dsl.rb', line 67 def relation(name, plan = nil, plans: nil, &block) if plans plans.each do |build_plan| forward_callbacks(@plan, build_plan.plan) end @plan.add_relation_union(name, plans.map(&:plan), &block) else plan ||= Plan.new(@plan.config) plan = plan.plan if plan.is_a?(BuiltPlan) dsl = Dsl.new(plan) dsl.instance_exec(&block) if block.present? forward_callbacks(@plan, plan) @plan.add_relation(name, dsl.plan) end end |
#wipe_out(*names, strategy: AttributeStrategies::Nullify, &block) ⇒ nil
Defines a strategy for removing data inside attribute(s)
56 57 58 59 60 61 |
# File 'lib/wipe_out/plans/dsl.rb', line 56 def wipe_out(*names, strategy: AttributeStrategies::Nullify, &block) strategy = block if block names.each do |name| plan.add_attribute(name, strategy: strategy) end end |