Class: Behavior

Inherits:
Object
  • Object
show all
Defined in:
lib/embed_callbacks/behavior.rb

Constant Summary collapse

KINDS =
%i(before after around rescue ensure)

Instance Method Summary collapse

Constructor Details

#initialize(behavior) ⇒ Behavior

Returns a new instance of Behavior.

Raises:

  • (ArgumentError)


4
5
6
7
# File 'lib/embed_callbacks/behavior.rb', line 4

def initialize(behavior)
  @behavior = behavior
  raise ArgumentError, 'The behavior should be set in the ' + KINDS.join(' ') unless KINDS.include?(behavior)
end

Instance Method Details

#after?Boolean



13
14
15
# File 'lib/embed_callbacks/behavior.rb', line 13

def after?
  %i(after around).include?(@behavior)
end

#before?Boolean



9
10
11
# File 'lib/embed_callbacks/behavior.rb', line 9

def before?
  %i(before around).include?(@behavior)
end

#ensure?Boolean



21
22
23
# File 'lib/embed_callbacks/behavior.rb', line 21

def ensure?
  :ensure == @behavior
end

#rescue?Boolean



17
18
19
# File 'lib/embed_callbacks/behavior.rb', line 17

def rescue?
  :rescue == @behavior
end