Module: HTTPTracker::ClassMethods

Included in:
Manager
Defined in:
lib/http_tracker/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#add(label, klass = nil, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/http_tracker/class_methods.rb', line 3

def add(label, klass = nil, &block)
  if label.is_a?(Class) || (klass.nil? && !block_given?)
    raise ArgumentError,
      "A class or a block should be passed along with the tracker label."
  end

  klass ||= Class.new
  if block_given?
    klass.class_eval(&block)
  end

  tracker = klass.new

  if !tracker.respond_to?(:on_request) && !tracker.respond_to?(:on_response)
    raise ArgumentError,
      "You should implement one of the following methods: on_response, on_request."
  end

  trackers[label] = klass
end

#clear!Object



28
29
30
# File 'lib/http_tracker/class_methods.rb', line 28

def clear!
  @trackers = {}
end

#trackersObject



24
25
26
# File 'lib/http_tracker/class_methods.rb', line 24

def trackers
  @trackers ||= {}
end