class Apia::Route

Constants

REQUEST_METHODS

Attributes

controller[R]
endpoint[W]
group[R]
path[R]
request_method[R]

Public Class Methods

new(path, **options) click to toggle source
# File lib/apia/route.rb, line 16
def initialize(path, **options)
  @path = path

  @group = options[:group]

  @controller = options[:controller]
  @endpoint = options[:endpoint]

  @request_method = options[:request_method] || :get
end

Public Instance Methods

endpoint() click to toggle source

Return the endpoint object for this route

@return [Apia::Endpoint]

# File lib/apia/route.rb, line 30
def endpoint
  if @endpoint.is_a?(Symbol) && controller
    return controller.definition.endpoints[@endpoint]
  end

  @endpoint
end
extract_arguments(given_path) click to toggle source

Extract arguments from the given path and return a hash of the arguments based on their naming from the route

@param given_path [String] @return [Hash]

# 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.each_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() click to toggle source

Return the parts for this route

@return [Array<String>]

# File lib/apia/route.rb, line 41
def path_parts
  @path_parts ||= RouteSet.split_path(@path)
end