Class: ChainOfResponsibility::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/chain_of_responsibility/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(successor = MissingSuccessor.new) ⇒ Handler

Returns a new instance of Handler.



8
9
10
# File 'lib/chain_of_responsibility/handler.rb', line 8

def initialize(successor = MissingSuccessor.new)
  @successor = successor
end

Instance Attribute Details

#successorObject (readonly)

Returns the value of attribute successor.



12
13
14
# File 'lib/chain_of_responsibility/handler.rb', line 12

def successor
  @successor
end

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)

Raises:



26
27
28
# File 'lib/chain_of_responsibility/handler.rb', line 26

def applicable?(*)
  raise MethodNotImplementedError, "applicable?"
end

#call(*args) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/chain_of_responsibility/handler.rb', line 14

def call(*args)
  if applicable?(*args)
    resolve(*args)
  else
    successor.call(*args)
  end
end

#resolveObject



22
23
24
# File 'lib/chain_of_responsibility/handler.rb', line 22

def resolve(*)
  raise MethodNotImplementedError, "resolve"
end