Class: Spectroscope::Hooks::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/spectroscope/hooks.rb

Overview

Encapsulates a hook procedure along with it’s match tags.

Instance Method Summary collapse

Constructor Details

#initialize(tense, scope, *tags, &proc) ⇒ Hook

A brief description of the advice (optional). attr :subject



77
78
79
80
81
82
# File 'lib/spectroscope/hooks.rb', line 77

def initialize(tense, scope, *tags, &proc)
  @tense = tense
  @scope = scope
  @tags  = tags
  @proc  = proc
end

Instance Method Details

#match?(it) ⇒ Boolean

Check for matching subjects or tags for each advice.

Returns:

  • (Boolean)


87
88
89
90
91
92
93
# File 'lib/spectroscope/hooks.rb', line 87

def match?(it)
  return true if @tags.empty?

  @tags.any? do |t|
    it.match?(t)
  end
end

#to_procObject



96
97
98
# File 'lib/spectroscope/hooks.rb', line 96

def to_proc
  @proc
end