class Pakyow::Endpoints
Lookup for endpoints.
Public Class Methods
new()
click to toggle source
# File lib/pakyow/endpoints.rb, line 14 def initialize @endpoints = [] end
Public Instance Methods
<<(endpoint)
click to toggle source
Adds an endpoint.
# File lib/pakyow/endpoints.rb, line 26 def <<(endpoint) @endpoints << endpoint end
find(name:)
click to toggle source
# File lib/pakyow/endpoints.rb, line 18 def find(name:) @endpoints.find { |endpoint| endpoint.name == name } end
load(object_with_endpoints)
click to toggle source
# 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)
click to toggle source
# File lib/pakyow/endpoints.rb, line 52 def method(name) endpoint_with_name(name)&.method end
path(name, hashlike_object = nil, **params)
click to toggle source
Builds the path to a named route.
@example Build the path to the new
route within the post
group:
path(:post_new) # => "/posts/new"
@example Build the path providing a value for post_id
:
path(:post_edit, post_id: 1) # => "/posts/1/edit"
# 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)
click to toggle source
Builds the path to a route, following a trail of names.
@example Build the path to the new
route within the post
group:
path_to(:post, :new) # => "/posts/new"
@example Build the path providing a value for post_id
:
path_to(:post, :edit, post_id: 1) # => "/posts/1/edit"
# File lib/pakyow/endpoints.rb, line 66 def path_to(*names, **params) path(names.join("_").to_sym, **params) end
Private Instance Methods
endpoint_with_name(name)
click to toggle source
# File lib/pakyow/endpoints.rb, line 72 def endpoint_with_name(name) name = name.to_sym @endpoints.find { |endpoint| endpoint.name == name } end