class Rory::Route

Attributes

action[R]
controller[R]
mask[R]

Public Class Methods

new(mask, options = {}) click to toggle source
# File lib/rory/route.rb, line 5
def initialize(mask, options = {})
  @mask = mask.gsub(/^\//, '')
  @options = options
  @controller, @action = options[:to].split('#')
end

Public Instance Methods

==(other) click to toggle source
# File lib/rory/route.rb, line 15
def ==(other)
  to_h == other.to_h
end
matches_request?(path, method) click to toggle source
# File lib/rory/route.rb, line 31
def matches_request?(path, method)
  @match = regex.match(path)
  @match &&
    (methods.empty? ||
      methods.include?(method.to_sym))
end
methods() click to toggle source
# File lib/rory/route.rb, line 27
def methods
  @options[:methods] || []
end
module() click to toggle source
# File lib/rory/route.rb, line 23
def module
  @options[:module]
end
name() click to toggle source
# File lib/rory/route.rb, line 11
def name
  "#{controller}_#{action}"
end
path_params(path) click to toggle source
# File lib/rory/route.rb, line 38
def path_params(path)
  @match ||= regex.match(path)
  symbolized_param_names = @match.names.map { |name| name.to_sym }
  Hash[symbolized_param_names.zip(@match.captures)]
end
regex() click to toggle source
# File lib/rory/route.rb, line 19
def regex
  /^#{@mask.gsub(/:([\w_]+)/, "(?<\\1>\[\^\\\/\]+)")}$/
end
to_h() click to toggle source
# File lib/rory/route.rb, line 44
def to_h
  {
    :mask => @mask,
    :controller => @controller,
    :action => @action,
    :module => @module,
    :methods => @methods
  }
end