Class: Loom::Pattern::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/pattern/hook.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, &block) ⇒ Hook

Returns a new instance of Hook.



18
19
20
21
22
23
24
# File 'lib/loom/pattern/hook.rb', line 18

def initialize(scope, &block)
  unless [:before, :around, :after].include? scope
    raise 'invalid Pattern::DSL hook scope'
  end
  @scope = scope
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



26
27
28
# File 'lib/loom/pattern/hook.rb', line 26

def block
  @block
end

#scopeObject (readonly)

Returns the value of attribute scope.



26
27
28
# File 'lib/loom/pattern/hook.rb', line 26

def scope
  @scope
end

Class Method Details

.after_hooks(hooks) ⇒ Object



13
14
15
# File 'lib/loom/pattern/hook.rb', line 13

def after_hooks(hooks)
  hooks.find_all { |h| h.scope == :after }
end

.around_hooks(hooks) ⇒ Object



5
6
7
# File 'lib/loom/pattern/hook.rb', line 5

def around_hooks(hooks)
  hooks.find_all { |h| h.scope == :around }
end

.before_hooks(hooks) ⇒ Object



9
10
11
# File 'lib/loom/pattern/hook.rb', line 9

def before_hooks(hooks)
  hooks.find_all { |h| h.scope == :before }
end