Class: Apia::Route
- Inherits:
-
Object
- Object
- Apia::Route
- Defined in:
- lib/apia/route.rb
Constant Summary collapse
- REQUEST_METHODS =
[:get, :post, :patch, :put, :delete].freeze
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#endpoint ⇒ Apia::Endpoint
Return the endpoint object for this route.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
Instance Method Summary collapse
-
#extract_arguments(given_path) ⇒ Hash
Extract arguments from the given path and return a hash of the arguments based on their naming from the route.
-
#initialize(path, **options) ⇒ Route
constructor
A new instance of Route.
-
#path_parts ⇒ Array<String>
Return the parts for this route.
Constructor Details
#initialize(path, **options) ⇒ Route
Returns a new instance of Route.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/apia/route.rb', line 16 def initialize(path, **) @path = path @group = [:group] @controller = [:controller] @endpoint = [:endpoint] @request_method = [:request_method] || :get end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
11 12 13 |
# File 'lib/apia/route.rb', line 11 def controller @controller end |
#endpoint ⇒ Apia::Endpoint
Return the endpoint object for this route
30 31 32 33 34 35 36 |
# File 'lib/apia/route.rb', line 30 def endpoint if @endpoint.is_a?(Symbol) && controller return controller.definition.endpoints[@endpoint] end @endpoint end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
13 14 15 |
# File 'lib/apia/route.rb', line 13 def group @group end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/apia/route.rb', line 10 def path @path end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
12 13 14 |
# File 'lib/apia/route.rb', line 12 def request_method @request_method end |
Instance Method Details
#extract_arguments(given_path) ⇒ Hash
Extract arguments from the given path and return a hash of the arguments based on their naming from the route
50 51 52 53 54 55 56 57 58 |
# File 'lib/apia/route.rb', line 50 def extract_arguments(given_path) given_path_parts = RouteSet.split_path(given_path) path_parts.each_with_index.with_object({}) do |(part, index), hash| next unless part =~ /\A:(\w+)/ value = given_path_parts[index] hash[Regexp.last_match[1]] = value end end |
#path_parts ⇒ Array<String>
Return the parts for this route
41 42 43 |
# File 'lib/apia/route.rb', line 41 def path_parts @path_parts ||= RouteSet.split_path(@path) end |