Class: Padrino::PathRouter::Route
- Defined in:
- padrino-core/lib/padrino-core/path_router/route.rb
Constant Summary collapse
- SIGNIFICANT_VARIABLES_REGEX =
/(^|[^\\])[:*]([a-zA-Z0-9_]+)/.freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
The accessors will be used in other classes.
-
#block ⇒ Object
readonly
A reader for compile option.
-
#cache ⇒ Object
The accessors will be used in other classes.
-
#cache_expires ⇒ Object
The accessors will be used in other classes.
-
#cache_key ⇒ Object
The accessors will be used in other classes.
-
#capture ⇒ Object
The accessors are useful to access from PathRouter::Router.
-
#controller ⇒ Object
The accessors will be used in other classes.
-
#default_values ⇒ Object
The accessors will be used in other classes.
-
#index ⇒ Object
The accessors are useful to access from PathRouter::Router.
-
#name ⇒ Object
The accessors are useful to access from PathRouter::Router.
-
#options ⇒ Object
The accessors are useful to access from PathRouter::Router.
-
#order ⇒ Object
The accessors are useful to access from PathRouter::Router.
-
#parent ⇒ Object
The accessors will be used in other classes.
-
#path_for_generation ⇒ Object
The accessors will be used in other classes.
-
#regexp ⇒ Object
The accessors are useful to access from PathRouter::Router.
-
#router ⇒ Object
writeonly
The router will be treated in this class.
-
#use_layout ⇒ Object
The accessors will be used in other classes.
-
#user_agent ⇒ Object
The accessors will be used in other classes.
-
#verb ⇒ Object
readonly
A reader for compile option.
Instance Method Summary collapse
-
#after_filters(&block) ⇒ Object
Returns after_filters as an array.
-
#before_filters(&block) ⇒ Object
Returns before_filters as an array.
-
#block_parameter_length ⇒ Object
Returns block parameter length.
-
#call(app, *args) ⇒ Object
Calls the route block with arguments.
-
#custom_conditions(&block) ⇒ Object
Returns custom_conditions as an array.
-
#initialize(path, verb, options = {}, &block) ⇒ Route
constructor
Constructs an instance of PathRouter::Route.
- #match(pattern) ⇒ Object
-
#matcher ⇒ Object
Returns an instance of PathRouter::Matcher that is associated with the route.
-
#original_path ⇒ Object
Returns the original path.
-
#params_for(pattern, others = {}) ⇒ Object
Returns parameters which is created by the matcher.
-
#path(*args) ⇒ Object
Expands the path by using parameters.
-
#path=(pattern) ⇒ Object
Overwrites path value by passing new path string.
-
#request_methods ⇒ Object
Returns the route’s verb as an array.
-
#significant_variable_names ⇒ Object
Returns signficant variable names.
-
#to(&block) ⇒ Object
Associates a block with the route, and increments current order of the router.
Constructor Details
#initialize(path, verb, options = {}, &block) ⇒ Route
Constructs an instance of PathRouter::Route.
28 29 30 31 32 33 34 35 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 28 def initialize(path, verb, = {}, &block) @path = path @verb = verb @capture = {} @order = 0 @block = block if block_given? () end |
Instance Attribute Details
#action ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def action @action end |
#block ⇒ Object (readonly)
A reader for compile option
12 13 14 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 12 def block @block end |
#cache ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def cache @cache end |
#cache_expires ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def cache_expires @cache_expires end |
#cache_key ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def cache_key @cache_key end |
#capture ⇒ Object
The accessors are useful to access from PathRouter::Router
7 8 9 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 7 def capture @capture end |
#controller ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def controller @controller end |
#default_values ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def default_values @default_values end |
#index ⇒ Object
The accessors are useful to access from PathRouter::Router
7 8 9 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 7 def index @index end |
#name ⇒ Object
The accessors are useful to access from PathRouter::Router
7 8 9 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 7 def name @name end |
#options ⇒ Object
The accessors are useful to access from PathRouter::Router
7 8 9 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 7 def @options end |
#order ⇒ Object
The accessors are useful to access from PathRouter::Router
7 8 9 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 7 def order @order end |
#parent ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def parent @parent end |
#path_for_generation ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def path_for_generation @path_for_generation end |
#regexp ⇒ Object
The accessors are useful to access from PathRouter::Router
7 8 9 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 7 def regexp @regexp end |
#router=(value) ⇒ Object (writeonly)
The router will be treated in this class
17 18 19 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 17 def router=(value) @router = value end |
#use_layout ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def use_layout @use_layout end |
#user_agent ⇒ Object
The accessors will be used in other classes
22 23 24 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 22 def user_agent @user_agent end |
#verb ⇒ Object (readonly)
A reader for compile option
12 13 14 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 12 def verb @verb end |
Instance Method Details
#after_filters(&block) ⇒ Object
Returns after_filters as an array.
136 137 138 139 140 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 136 def after_filters(&block) @_after_filters ||= [] @_after_filters << block if block_given? @_after_filters end |
#before_filters(&block) ⇒ Object
Returns before_filters as an array.
127 128 129 130 131 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 127 def before_filters(&block) @_before_filters ||= [] @_before_filters << block if block_given? @_before_filters end |
#block_parameter_length ⇒ Object
Returns block parameter length.
154 155 156 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 154 def block_parameter_length matcher.capture_length end |
#call(app, *args) ⇒ Object
Calls the route block with arguments.
40 41 42 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 40 def call(app, *args) @block.call(app, *args) end |
#custom_conditions(&block) ⇒ Object
Returns custom_conditions as an array.
145 146 147 148 149 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 145 def custom_conditions(&block) @_custom_conditions ||= [] @_custom_conditions << block if block_given? @_custom_conditions end |
#match(pattern) ⇒ Object
84 85 86 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 84 def match(pattern) matcher.match(pattern) end |
#matcher ⇒ Object
Returns an instance of PathRouter::Matcher that is associated with the route.
77 78 79 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 77 def matcher @matcher ||= Matcher.new(@path, :capture => @capture, :default_values => default_values) end |
#original_path ⇒ Object
Returns the original path.
54 55 56 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 54 def original_path @path end |
#params_for(pattern, others = {}) ⇒ Object
Returns parameters which is created by the matcher.
120 121 122 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 120 def params_for(pattern, others = {}) matcher.params_for(pattern, others) end |
#path(*args) ⇒ Object
Expands the path by using parameters.
101 102 103 104 105 106 |
# File 'padrino-core/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.(params) if matcher.mustermann? end |
#path=(pattern) ⇒ Object
Overwrites path value by passing new path string.
111 112 113 114 115 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 111 def path=(pattern) @path = pattern @matcher = nil @significant_variable_names = nil end |
#request_methods ⇒ Object
Returns the route’s verb as an array.
47 48 49 |
# File 'padrino-core/lib/padrino-core/path_router/route.rb', line 47 def request_methods [verb.to_s.upcase] end |
#significant_variable_names ⇒ Object
Returns signficant variable names.
63 64 65 66 67 68 69 70 71 72 |
# File 'padrino-core/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 |
#to(&block) ⇒ Object
Associates a block with the route, and increments current order of the router.
91 92 93 94 95 |
# File 'padrino-core/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 |