Class: Aikido::Zen::Route

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

Overview

Routes keep information about the mapping defined in the current web framework to go from a given HTTP request to the code that handles said request.

Direct Known Subclasses

Aikido::Zen::Rails::Route

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb:, path:) ⇒ Route

Returns a new instance of Route.



15
16
17
18
# File 'lib/aikido/zen/route.rb', line 15

def initialize(verb:, path:)
  @verb = verb
  @path = path
end

Instance Attribute Details

#pathString (readonly)

Returns the URL pattern used to match request paths. For example “/users/:id”.

Returns:

  • (String)

    the URL pattern used to match request paths. For example “/users/:id”.



13
14
15
# File 'lib/aikido/zen/route.rb', line 13

def path
  @path
end

#verbString (readonly)

Returns the HTTP verb used to request this route.

Returns:

  • (String)

    the HTTP verb used to request this route.



9
10
11
# File 'lib/aikido/zen/route.rb', line 9

def verb
  @verb
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



24
25
26
27
28
# File 'lib/aikido/zen/route.rb', line 24

def ==(other)
  other.is_a?(Route) &&
    other.verb == verb &&
    other.path == path
end

#as_jsonObject



20
21
22
# File 'lib/aikido/zen/route.rb', line 20

def as_json
  {method: verb, path: path}
end

#hashObject



31
32
33
# File 'lib/aikido/zen/route.rb', line 31

def hash
  [verb, path].hash
end

#inspectObject



35
36
37
# File 'lib/aikido/zen/route.rb', line 35

def inspect
  "#<#{self.class.name} #{verb} #{path.inspect}>"
end