class Tennpipes::PathRouter::Route

Constants

SIGNIFICANT_VARIABLES_REGEX

Attributes

action[RW]

The accessors will be used in other classes

block[R]

A reader for compile option

cache[RW]

The accessors will be used in other classes

cache_expires[RW]

The accessors will be used in other classes

cache_key[RW]

The accessors will be used in other classes

capture[RW]

The accessors are useful to access from PathRouter::Router

controller[RW]

The accessors will be used in other classes

default_values[RW]

The accessors will be used in other classes

index[RW]

The accessors are useful to access from PathRouter::Router

name[RW]

The accessors are useful to access from PathRouter::Router

options[RW]

The accessors are useful to access from PathRouter::Router

order[RW]

The accessors are useful to access from PathRouter::Router

parent[RW]

The accessors will be used in other classes

path_for_generation[RW]

The accessors will be used in other classes

router[W]

The router will be treated in this class

use_layout[RW]

The accessors will be used in other classes

user_agent[RW]

The accessors will be used in other classes

verb[R]

A reader for compile option

Public Class Methods

new(path, verb, options = {}, &block) click to toggle source

Constructs an instance of PathRouter::Route.

# File lib/tennpipes-base/path_router/route.rb, line 28
def initialize(path, verb, options = {}, &block)
  @path = path
  @verb = verb
  @capture = {}
  @order   = 0
  @block   = block if block_given?
  merge_with_options!(options)
end

Public Instance Methods

after_filters(&block) click to toggle source

Returns after_filters as an array.

# File lib/tennpipes-base/path_router/route.rb, line 127
def after_filters(&block)
  @_after_filters ||= []
  @_after_filters << block if block_given?
  @_after_filters
end
before_filters(&block) click to toggle source

Returns before_filters as an array.

# File lib/tennpipes-base/path_router/route.rb, line 118
def before_filters(&block)
  @_before_filters ||= []
  @_before_filters << block if block_given?
  @_before_filters
end
block_parameter_length() click to toggle source

Returns block parameter length.

# File lib/tennpipes-base/path_router/route.rb, line 145
def block_parameter_length
  matcher.capture_length
end
call(app, *args) click to toggle source

Calls the route block with arguments.

# File lib/tennpipes-base/path_router/route.rb, line 40
def call(app, *args)
  @block.call(app, *args)
end
custom_conditions(&block) click to toggle source

Returns custom_conditions as an array.

# File lib/tennpipes-base/path_router/route.rb, line 136
def custom_conditions(&block)
  @_custom_conditions ||= []
  @_custom_conditions << block if block_given?
  @_custom_conditions
end
match(pattern) click to toggle source

@see PathRouter::Matcher#match

# File lib/tennpipes-base/path_router/route.rb, line 84
def match(pattern)
  matcher.match(pattern)
end
matcher() click to toggle source

Returns an instance of PathRouter::Matcher that is associated with the route.

# File lib/tennpipes-base/path_router/route.rb, line 77
def matcher
  @matcher ||= Matcher.new(@path, :capture => @capture, :default_values => default_values)
end
original_path() click to toggle source

Returns the original path.

# File lib/tennpipes-base/path_router/route.rb, line 54
def original_path
  @path
end
params_for(pattern, others = {}) click to toggle source

Returns parameters which is created by the matcher.

# File lib/tennpipes-base/path_router/route.rb, line 111
def params_for(pattern, others = {})
  matcher.params_for(pattern, others)
end
path(*args) click to toggle source

Expands the path by using parameters. @see PathRouter::Matcher#expand

# File lib/tennpipes-base/path_router/route.rb, line 101
def path(*args)
  return @path if args.empty?
  params = args[0].dup
  params.delete(:captures)
  matcher.expand(params) if matcher.mustermann?
end
request_methods() click to toggle source

Returns the route's verb as an array.

# File lib/tennpipes-base/path_router/route.rb, line 47
def request_methods
  [verb.to_s.upcase]
end
significant_variable_names() click to toggle source

Returns signficant variable names.

# File lib/tennpipes-base/path_router/route.rb, line 63
def significant_variable_names
  @significant_variable_names ||=
    if @path.is_a?(String)
      @path.scan(SIGNIFICANT_VARIABLES_REGEX).map{ |p| p.last.to_sym }
    elsif @path.is_a?(Regexp) and @path.respond_to?(:named_captures)
      @path.named_captures.keys.map(&:to_sym)
    else
      []
    end
end
to(&block) click to toggle source

Associates a block with the route, and increments current order of the router.

# File lib/tennpipes-base/path_router/route.rb, line 91
def to(&block)
  @block = block if block_given?
  @order = @router.current_order
  @router.increment_order
end

Private Instance Methods

accessor?(key) click to toggle source

Returns true if name has been defined as an accessor.

# File lib/tennpipes-base/path_router/route.rb, line 164
def accessor?(key)
  respond_to?("#{key}=") && respond_to?(key)
end
merge_with_options!(options) click to toggle source

Set value to accessor if option name has been defined as an accessora.

# File lib/tennpipes-base/path_router/route.rb, line 154
def merge_with_options!(options)
  @options ||= {}
  options.each_pair do |key, value|
    accessor?(key) ? __send__("#{key}=", value) : (@options[key] = value)
  end
end