Class: WipeOut::Plans::Plan

Inherits:
Object
  • Object
show all
Defined in:
lib/wipe_out/plans/plan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Plan

Returns a new instance of Plan.



4
5
6
7
8
9
10
11
# File 'lib/wipe_out/plans/plan.rb', line 4

def initialize(config)
  @attributes = {}
  @ignored = []
  @callbacks = []
  @relations = {}
  @on_execute = nil
  @config = config
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/wipe_out/plans/plan.rb', line 13

def attributes
  @attributes
end

#callbacksObject (readonly)

Returns the value of attribute callbacks.



13
14
15
# File 'lib/wipe_out/plans/plan.rb', line 13

def callbacks
  @callbacks
end

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/wipe_out/plans/plan.rb', line 13

def config
  @config
end

#ignoredObject (readonly)

Returns the value of attribute ignored.



13
14
15
# File 'lib/wipe_out/plans/plan.rb', line 13

def ignored
  @ignored
end

#relationsObject (readonly)

Returns the value of attribute relations.



13
14
15
# File 'lib/wipe_out/plans/plan.rb', line 13

def relations
  @relations
end

Instance Method Details

#add_attribute(name, strategy:) ⇒ Object



15
16
17
# File 'lib/wipe_out/plans/plan.rb', line 15

def add_attribute(name, strategy:)
  @attributes[name.to_sym] = strategy
end

#add_callback(callback) ⇒ Object



54
55
56
# File 'lib/wipe_out/plans/plan.rb', line 54

def add_callback(callback)
  @callbacks << callback
end

#add_relation(name, plan) ⇒ Object



19
20
21
# File 'lib/wipe_out/plans/plan.rb', line 19

def add_relation(name, plan)
  @relations[name.to_sym] = plan
end

#add_relation_union(name, plans, &block) ⇒ Object



23
24
25
# File 'lib/wipe_out/plans/plan.rb', line 23

def add_relation_union(name, plans, &block)
  @relations[name.to_sym] = Union.new(plans, block)
end

#establish_execution_plan(_record) ⇒ Object



50
51
52
# File 'lib/wipe_out/plans/plan.rb', line 50

def establish_execution_plan(_record)
  self
end

#ignore(name) ⇒ Object



31
32
33
# File 'lib/wipe_out/plans/plan.rb', line 31

def ignore(name)
  @ignored << name.to_sym
end

#include_plan(other) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/wipe_out/plans/plan.rb', line 35

def include_plan(other)
  @attributes.merge! other.attributes
  @ignored += other.ignored
  @relations.merge! other.relations
  @on_execute = other.on_execute
  other.callbacks.each do |callback|
    @callbacks << callback
  end
end

#inspectObject



58
59
60
# File 'lib/wipe_out/plans/plan.rb', line 58

def inspect
  "Plan(attributes=#{attributes.keys})"
end

#on_execute(arg = nil, &block) ⇒ Object



27
28
29
# File 'lib/wipe_out/plans/plan.rb', line 27

def on_execute(arg = nil, &block)
  @on_execute = arg || block || @on_execute
end

#plansObject

Duck typing for plans union



46
47
48
# File 'lib/wipe_out/plans/plan.rb', line 46

def plans
  [self]
end