Class: Pakyow::Endpoints
- Inherits:
-
Object
- Object
- Pakyow::Endpoints
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/pakyow/endpoints.rb
Overview
Lookup for endpoints.
Instance Method Summary collapse
-
#<<(endpoint) ⇒ Object
Adds an endpoint.
- #find(name:) ⇒ Object
-
#initialize ⇒ Endpoints
constructor
A new instance of Endpoints.
- #load(object_with_endpoints) ⇒ Object
- #method(name) ⇒ Object
-
#path(name, hashlike_object = nil, **params) ⇒ Object
Builds the path to a named route.
-
#path_to(*names, **params) ⇒ Object
Builds the path to a route, following a trail of names.
Constructor Details
#initialize ⇒ Endpoints
Returns a new instance of Endpoints.
14 15 16 |
# File 'lib/pakyow/endpoints.rb', line 14 def initialize @endpoints = [] end |
Instance Method Details
#<<(endpoint) ⇒ Object
Adds an endpoint.
26 27 28 |
# File 'lib/pakyow/endpoints.rb', line 26 def <<(endpoint) @endpoints << endpoint end |
#find(name:) ⇒ Object
18 19 20 21 22 |
# File 'lib/pakyow/endpoints.rb', line 18 def find(name:) @endpoints.find { |endpoint| endpoint.name == name } end |
#load(object_with_endpoints) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/pakyow/endpoints.rb', line 30 def load(object_with_endpoints) if object_with_endpoints.respond_to?(:endpoints) object_with_endpoints.endpoints.each do |endpoint| self << endpoint end end end |
#method(name) ⇒ Object
52 53 54 |
# File 'lib/pakyow/endpoints.rb', line 52 def method(name) endpoint_with_name(name)&.method end |
#path(name, hashlike_object = nil, **params) ⇒ Object
Builds the path to a named route.
48 49 50 |
# File 'lib/pakyow/endpoints.rb', line 48 def path(name, hashlike_object = nil, **params) endpoint_with_name(name)&.path(hashlike_object, **params) end |
#path_to(*names, **params) ⇒ Object
Builds the path to a route, following a trail of names.
66 67 68 |
# File 'lib/pakyow/endpoints.rb', line 66 def path_to(*names, **params) path(names.join("_").to_sym, **params) end |