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 Attribute Summary collapse

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.



14
15
16
17
# File 'lib/aikido/zen/collector/routes.rb', line 14

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

Instance Attribute Details

#visitsObject (readonly)

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.

Visible for testing.



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

def visits
  @visits
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.

Visible for testing.



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

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

#add(route, schema) ⇒ void

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.

This method returns an undefined value.

Parameters:



22
23
24
# File 'lib/aikido/zen/collector/routes.rb', line 22

def add(route, schema)
  @visits[route].increment(schema) unless route.nil?
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.



26
27
28
29
30
31
32
33
34
35
# File 'lib/aikido/zen/collector/routes.rb', line 26

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)


44
45
46
# File 'lib/aikido/zen/collector/routes.rb', line 44

def empty?
  @visits.empty?
end