forked from railslove/rack-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_delegator.rb
More file actions
40 lines (33 loc) · 869 Bytes
/
handler_delegator.rb
File metadata and controls
40 lines (33 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Rack::Tracker::HandlerDelegator
class << self
def handler(method_name)
new.handler(method_name)
end
end
attr_accessor :env
def initialize(env = {})
@env = env
end
def method_missing(method_name, *args, &block)
if respond_to?(method_name)
handler(method_name).process_track(env, method_name, *args, &block)
else
super
end
end
def respond_to?(method_name, include_private = false)
handler(method_name).respond_to?(:track, include_private)
end
def handler(method_name)
return method_name if method_name.kind_of?(Class)
_handler = method_name.to_s.camelize
["Rack::Tracker::#{_handler}", _handler].detect do |const|
begin
return const.constantize
rescue NameError
false
end
end
raise ArgumentError, "No such Handler: #{_handler}"
end
end