class WipeOut::Plans::Dsl

Provides DSL methods available during {Plan} building.

Attributes

plan[R]

@!visibility private

Public Class Methods

build(plan, &block) click to toggle source

{#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
new(plan) click to toggle source

@!visibility private

# File lib/wipe_out/plans/dsl.rb, line 40
def initialize(plan)
  @plan = plan
end

Public Instance Methods

add_callback(callback) click to toggle source

@!visibility private

# File lib/wipe_out/plans/dsl.rb, line 112
def add_callback(callback)
  plan.add_callback(callback)
end
configure() { |config| ... } click to toggle source

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
ignore(*names) click to toggle source

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
ignore_all() click to toggle source

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
include_plan(built_plan) click to toggle source
# File lib/wipe_out/plans/dsl.rb, line 98
def include_plan(built_plan)
  plan.include_plan(built_plan.plan)
end
plugin(plugin) click to toggle source

@!visibility private

# File lib/wipe_out/plans/dsl.rb, line 45
def plugin(plugin)
  plugin.callbacks.each { |callback| add_callback(callback) }
end
relation(name, plan = nil, plans: nil, &block) click to toggle source

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
wipe_out(*names, strategy: AttributeStrategies::Nullify, &block) click to toggle source

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