Class: Hijacker::Handler

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped
Defined in:
lib/hijacker/handler.rb

Direct Known Subclasses

Logger

Constant Summary collapse

@@handlers =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Handler

Returns a new instance of Handler.



20
21
22
# File 'lib/hijacker/handler.rb', line 20

def initialize(opts)
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



19
20
21
# File 'lib/hijacker/handler.rb', line 19

def opts
  @opts
end

Class Method Details

.handlersObject



53
54
55
# File 'lib/hijacker/handler.rb', line 53

def handlers
  @@handlers
end

.register_handler(handler) ⇒ Object



48
49
50
51
52
# File 'lib/hijacker/handler.rb', line 48

def register_handler(handler)
  handler.match(/handlers\/(\w+)/)
  handler = $1.strip if $1
  @@handlers << handler
end

Instance Method Details

#handle(method, args, retval, raised, object) ⇒ Object

Raises:

  • (NotImplementedError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hijacker/handler.rb', line 24

def handle(method, args, retval, raised, object)
  # Parameters received
  #
  #   method    :foo
  #
  #   args      [{:inspect => '3', :class => 'Fixnum'},
  #              {:inspect => '"string"', :class => 'String'}]
  #
  #   retval    {:inspect => ':bar', :class => 'Symbol'}
  # 
  #   - In case the method raised something, retval will be nil,
  #    and the exception info will be available in raised:
  #
  #   raised    {:inspect => 'wrong number of arguments (0 for 2)', :class => 'ArgumentError'}
  #
  #   object    {:inspect => '#<MyClass:0x003457>', :class => 'MyClass'}
  #
  raise NotImplementedError.new("You are supposed to subclass Handler")
end