class CptHook::DSL::HookDefinitions

Public Class Methods

new() click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 5
def initialize
  @hooks = []
end

Public Instance Methods

after(method_to_hook, &block) click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 21
def after(method_to_hook, &block)
  _hook_definition(method_to_hook, :after, &block)
end
before(method_to_hook, &block) click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 17
def before(method_to_hook, &block)
  _hook_definition(method_to_hook, :before, &block)
end
clone(other) click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 25
def clone(other)
  @hooks = other.hooks.map { |h| h.dup }
  self
end
dup() click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 30
def dup
  HookDefinitions.new.clone(self)
end
hooked_methods() click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 13
def hooked_methods
  @hooks.map { |h| h.method }.uniq
end
hooks(hook_type = nil) click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 9
def hooks(hook_type = nil)
  hook_type.nil? ? @hooks : @hooks.select { |h| h.hook_type == hook_type }
end
merge(other) click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 34
def merge(other)
  dup.merge!(other)
end
merge!(other) click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 38
def merge!(other)
  other.hooks.each do |hook|
    my_hook = @hooks.find { |h| (h.method == hook.method) && (h.hook_type == hook.hook_type) }
    if my_hook
      my_hook.merge!(hook)
    else
      @hooks << hook
    end
  end
  self
end

Private Instance Methods

_hook_definition(method_to_hook, hook_type, &block) click to toggle source
# File lib/cpt_hook/dsl/hook_definitions.rb, line 52
def _hook_definition(method_to_hook, hook_type, &block)
  hook_def = HookDefinition.new(method_to_hook, hook_type)
  @hooks << hook_def
  hook_def.instance_eval(&block) if block_given?
  hook_def
end