class RoadForest::Application::Parameters

Parameters extracted from a URL, which a interface object can use to identify the resource being discussed

Attributes

path_info[RW]
path_tokens[RW]
query_params[RW]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/roadforest/application/parameters.rb, line 6
def initialize
  @path_info = {}
  @query_params = {}
  @path_tokens = []
  yield self if block_given?
end

Public Instance Methods

[](field_name) click to toggle source
# File lib/roadforest/application/parameters.rb, line 14
def [](field_name)
  fetch(field_name)
rescue KeyError
  nil
end
fetch(field_name) click to toggle source
# File lib/roadforest/application/parameters.rb, line 20
def fetch(field_name)
  return path_tokens if field_name == '*'
  @path_info.fetch(field_name) do
    if @query_params.respond_to?(:fetch)
      @query_params.fetch(field_name) do
        @query_params.fetch(field_name.to_s)
      end
    else
      raise KeyError, "No parameter: #{field_name}"
    end
  end
end
remainder() click to toggle source
# File lib/roadforest/application/parameters.rb, line 39
def remainder
  @remainder = @path_tokens.join("/")
end
slice(*fields) click to toggle source
# File lib/roadforest/application/parameters.rb, line 33
def slice(*fields)
  fields.each_with_object({}) do |name, hash|
    hash[name] = self[name]
  end
end
to_hash() click to toggle source
# File lib/roadforest/application/parameters.rb, line 43
def to_hash
  (query_params||{}).merge(path_info||{}).merge('*' => path_tokens)
end