class WipeOut::Plans::Dsl
Provides DSL methods available during {Plan} building.
Attributes
@!visibility private
Public Class Methods
{#WipeOut.build_plan WipeOut.build_plan
} should be used instead
@!visibility private
# File lib/wipe_out/plans/dsl.rb, line 12 def self.build(plan, &block) dsl = Dsl.new(plan) dsl.instance_exec(&block) BuiltPlan.new(dsl.plan) end
@!visibility private
# File lib/wipe_out/plans/dsl.rb, line 40 def initialize(plan) @plan = plan end
Public Instance Methods
@!visibility private
# File lib/wipe_out/plans/dsl.rb, line 112 def add_callback(callback) plan.add_callback(callback) end
See {Config} to check what options are available. @todo add test for nested configurations inside plans @return [Config]
# File lib/wipe_out/plans/dsl.rb, line 105 def configure yield plan.config plan.config end
Sets given attribute(s) as ignored. Attributes must be ignored explicily otherwise errors will be raised during validation
@param names [Array<Symbol>] any number of attributes to ignore @return [nil]
# File lib/wipe_out/plans/dsl.rb, line 85 def ignore(*names) names.each do |name| plan.ignore(name) end end
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
# File lib/wipe_out/plans/dsl.rb, line 94 def ignore_all plan.ignore(WipeOut::IGNORE_ALL) end
# File lib/wipe_out/plans/dsl.rb, line 98 def include_plan(built_plan) plan.include_plan(built_plan.plan) end
@!visibility private
# File lib/wipe_out/plans/dsl.rb, line 45 def plugin(plugin) plugin.callbacks.each { |callback| add_callback(callback) } end
Configures plan for wiping out data in relation. You must pass a block and use the same DSL to configure it.
@return [nil]
# File lib/wipe_out/plans/dsl.rb, line 67 def relation(name, plan = nil, plans: nil, &block) if plans @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? @plan.add_relation(name, dsl.plan) end end
Defines a strategy for removing data inside attribute(s)
@param names [Array<Symbol>] any number of attributes to wipe out @param strategy [#call] defined a strategy which should be used for wiping out the attribute(s).
You can also define a strategy inline by passing a block. By default it uses {AttributeStrategies::Nullify}.
@return [nil]
# 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