forked from railslove/rack-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.rb
More file actions
35 lines (28 loc) · 884 Bytes
/
handler.rb
File metadata and controls
35 lines (28 loc) · 884 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
class Rack::Tracker::Handler
class_attribute :position_options
self.position_options = { head: :append }
attr_accessor :options
attr_accessor :env
def initialize(env, options = {})
self.env = env
self.options = options
self.position_options = options[:position] if options[:position]
end
def events
events = env.fetch('tracker', {})[self.class.to_s.demodulize.underscore] || []
events.map{ |ev| "#{self.class}::#{ev['class_name']}".constantize.new(ev.except('class_name')) }
end
def render
raise NotImplementedError.new('needs implementation')
end
def self.track(name, event)
raise NotImplementedError.new("class method `#{__callee__}` is not implemented.")
end
def self.position(options=nil)
self.position_options = options if options
self.position_options
end
def position
self.position_options
end
end