Class: WipeOut::Plans::Dsl

Inherits:
Object
  • Object
show all
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

Methods included from WipeOut::Plugin::ClassMethods

#after, #before, #callback, #callbacks

Instance Method Details

#configure {|plan.config| ... } ⇒ Config

TODO:

add test for nested configurations inside plans

See Config to check what options are available.

Yields:

  • (plan.config)

Returns:



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

Parameters:

  • names (Array<Symbol>)

    any number of attributes to ignore

Returns:

  • (nil)


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_allObject

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.

Parameters:

Returns:

  • (nil)


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

Yields:

Returns:

  • (nil)


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.

Returns:

  • (nil)


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)

Parameters:

  • names (Array<Symbol>)

    any number of attributes to wipe out

  • strategy (#call) (defaults to: AttributeStrategies::Nullify)

    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.

Returns:

  • (nil)


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