Class: Aikido::Zen::Collector::Routes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/collector/routes.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Keeps track of the visited routes.

Defined Under Namespace

Classes: Record

Instance Method Summary collapse

Constructor Details

#initialize(config = Aikido::Zen.config) ⇒ Routes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Routes.



10
11
12
13
# File 'lib/aikido/zen/collector/routes.rb', line 10

def initialize(config = Aikido::Zen.config)
  @config = config
  @visits = Hash.new { |h, k| h[k] = Record.new }
end

Instance Method Details

#[](route) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/aikido/zen/collector/routes.rb', line 34

def [](route)
  @visits[route]
end

#add(request) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (self)


17
18
19
20
# File 'lib/aikido/zen/collector/routes.rb', line 17

def add(request)
  @visits[request.route].increment(request) unless request.route.nil?
  self
end

#as_jsonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
# File 'lib/aikido/zen/collector/routes.rb', line 22

def as_json
  @visits.map do |route, record|
    {
      method: route.verb,
      path: route.path,
      hits: record.hits,
      apispec: record.schema.as_json
    }.compact
  end
end

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


39
40
41
# File 'lib/aikido/zen/collector/routes.rb', line 39

def empty?
  @visits.empty?
end