Class: CptHook::DSL::HookDefinition
- Inherits:
-
Object
- Object
- CptHook::DSL::HookDefinition
- Defined in:
- lib/cpt_hook/dsl/hook_definition.rb
Instance Attribute Summary collapse
-
#call_chain ⇒ Object
readonly
Returns the value of attribute call_chain.
-
#hook_type ⇒ Object
readonly
Returns the value of attribute hook_type.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #call(method_to_call) ⇒ Object
- #clone(other) ⇒ Object
- #contexts(*args) ⇒ Object
- #dup ⇒ Object
-
#initialize(method_to_hook, type) ⇒ HookDefinition
constructor
A new instance of HookDefinition.
- #merge(other) ⇒ Object
- #merge!(other) ⇒ Object
- #using(*args) ⇒ Object
- #with(*args) ⇒ Object
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_chain ⇒ Object (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_type ⇒ Object (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 |
#method ⇒ Object (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 |
#clone(other) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 38 def clone(other) @call_chain = other.call_chain.map { |cc| cc.dup } @hook_type = other.hook_type @method = other.method 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.concat args self end |
#dup ⇒ Object
34 35 36 |
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 34 def dup HookDefinition.new(@method, @hook_type).clone(self) end |
#merge(other) ⇒ Object
45 46 47 |
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 45 def merge(other) dup.merge!(other) end |
#merge!(other) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/cpt_hook/dsl/hook_definition.rb', line 49 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 |