Class: CptHook::DSL::HookDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/cpt_hook/dsl/hook_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_to_hook, type) ⇒ HookDefinition

Returns a new instance of HookDefinition.



8
9
10
11
12
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 8

def initialize(method_to_hook, type)
  @method     = method_to_hook
  @hook_type  = type
  @call_chain = []
end

Instance Attribute Details

#call_chainObject (readonly)

Returns the value of attribute call_chain.



6
7
8
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 6

def call_chain
  @call_chain
end

#hook_typeObject (readonly)

Returns the value of attribute hook_type.



6
7
8
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 6

def hook_type
  @hook_type
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 6

def method
  @method
end

Instance Method Details

#call(method_to_call) ⇒ Object



14
15
16
17
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 14

def call(method_to_call)
  @call_chain << MethodCall.new(method_to_call)
  self
end

#contexts(*args) ⇒ Object



29
30
31
32
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 29

def contexts(*args)
  @call_chain.last.contexts(*args)
  self
end

#merge!(other) ⇒ Object



34
35
36
37
38
39
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 34

def merge!(other)
  other.call_chain.each do |cc|
    @call_chain << cc unless @call_chain.any? { |c| c.method == cc.method }
  end
  self
end

#using(*args) ⇒ Object



24
25
26
27
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 24

def using(*args)
  @call_chain.last.using(*args)
  self
end

#with(*args) ⇒ Object



19
20
21
22
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 19

def with(*args)
  @call_chain.last.with(*args)
  self
end