class Padrino::PathRouter::Route
Constants
- SIGNIFICANT_VARIABLES_REGEX
Attributes
The accessors will be used in other classes
A reader for compile option
The accessors will be used in other classes
The accessors will be used in other classes
The accessors will be used in other classes
The accessors are useful to access from PathRouter::Router
The accessors will be used in other classes
The accessors will be used in other classes
The accessors are useful to access from PathRouter::Router
The accessors are useful to access from PathRouter::Router
The accessors are useful to access from PathRouter::Router
The accessors are useful to access from PathRouter::Router
The accessors will be used in other classes
The accessors will be used in other classes
The accessors are useful to access from PathRouter::Router
The router will be treated in this class
The accessors will be used in other classes
The accessors will be used in other classes
A reader for compile option
Public Class Methods
Constructs an instance of PathRouter::Route
.
# File lib/padrino-core/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
Returns after_filters
as an array.
# File lib/padrino-core/path_router/route.rb, line 136 def after_filters(&block) @_after_filters ||= [] @_after_filters << block if block_given? @_after_filters end
Returns before_filters
as an array.
# File lib/padrino-core/path_router/route.rb, line 127 def before_filters(&block) @_before_filters ||= [] @_before_filters << block if block_given? @_before_filters end
Returns block parameter length.
# File lib/padrino-core/path_router/route.rb, line 154 def block_parameter_length matcher.capture_length end
Calls the route block with arguments.
# File lib/padrino-core/path_router/route.rb, line 40 def call(app, *args) @block.call(app, *args) end
Returns custom_conditions
as an array.
# File lib/padrino-core/path_router/route.rb, line 145 def custom_conditions(&block) @_custom_conditions ||= [] @_custom_conditions << block if block_given? @_custom_conditions end
@see PathRouter::Matcher#match
# File lib/padrino-core/path_router/route.rb, line 84 def match(pattern) matcher.match(pattern) end
Returns an instance of PathRouter::Matcher
that is associated with the route.
# File lib/padrino-core/path_router/route.rb, line 77 def matcher @matcher ||= Matcher.new(@path, :capture => @capture, :default_values => default_values) end
Returns the original path.
# File lib/padrino-core/path_router/route.rb, line 54 def original_path @path end
Returns parameters which is created by the matcher.
# File lib/padrino-core/path_router/route.rb, line 120 def params_for(pattern, others = {}) matcher.params_for(pattern, others) end
Expands the path by using parameters. @see PathRouter::Matcher#expand
# File lib/padrino-core/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
Overwrites path value by passing new path string.
# File lib/padrino-core/path_router/route.rb, line 111 def path=(pattern) @path = pattern @matcher = nil @significant_variable_names = nil end
Returns the route's verb as an array.
# File lib/padrino-core/path_router/route.rb, line 47 def request_methods [verb.to_s.upcase] end
Returns signficant variable names.
# File lib/padrino-core/path_router/route.rb, line 63 def significant_variable_names @significant_variable_names ||= if @path.is_a?(String) @path.scan(SIGNIFICANT_VARIABLES_REGEX).map(&:last) elsif @path.is_a?(Regexp) and @path.respond_to?(:named_captures) @path.named_captures.keys else [] end end
Associates a block with the route, and increments current order of the router.
# File lib/padrino-core/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
Returns true if name has been defined as an accessor.
# File lib/padrino-core/path_router/route.rb, line 173 def accessor?(key) respond_to?("#{key}=") && respond_to?(key) end
Set value to accessor if option name has been defined as an accessora.
# File lib/padrino-core/path_router/route.rb, line 163 def merge_with_options!(options) @options ||= {} options.each_pair do |key, value| accessor?(key) ? __send__("#{key}=", value) : (@options[key] = value) end end