Class: Rack::Mount::Route
- Inherits:
-
Object
- Object
- Rack::Mount::Route
- Extended by:
- Mixover
- Includes:
- Generation::Route, Rack::Mount::Recognition::Route
- Defined in:
- lib/rack/mount/route.rb
Overview
Route is an internal class used to wrap a single route attributes.
Plugins should not depend on any method on this class or instantiate new Route objects. Instead use the factory method, RouteSet#add_route to create new routes and add them to the set.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Valid rack application to call if conditions are met.
-
#conditions ⇒ Object
readonly
A hash of conditions to match against.
-
#defaults ⇒ Object
readonly
A hash of values that always gets merged into the parameters hash.
-
#name ⇒ Object
readonly
Symbol identifier for the route used with named route generations.
Attributes included from Rack::Mount::Recognition::Route
Instance Method Summary collapse
-
#initialize(app, conditions, defaults, name) ⇒ Route
constructor
A new instance of Route.
-
#inspect ⇒ Object
:nodoc:.
Methods included from Mixover
include, new, new_with_module, new_without_module
Methods included from Generation::Route
#generate, #generation_keys, #significant_params?
Methods included from Rack::Mount::Recognition::Route
Constructor Details
#initialize(app, conditions, defaults, name) ⇒ Route
Returns a new instance of Route.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rack/mount/route.rb', line 30 def initialize(app, conditions, defaults, name) unless app.respond_to?(:call) raise ArgumentError, 'app must be a valid rack application' \ ' and respond to call' end @app = app @name = name ? name.to_sym : nil @defaults = (defaults || {}).freeze @conditions = {} conditions.each do |method, pattern| next unless method && pattern pattern = Regexp.compile("\\A#{Regexp.escape(pattern)}\\Z") if pattern.is_a?(String) if pattern.is_a?(Regexp) pattern = Utils.normalize_extended_expression(pattern) pattern = RegexpWithNamedGroups.new(pattern) pattern.extend(GeneratableRegexp::InstanceMethods) pattern.defaults = @defaults end @conditions[method] = pattern.freeze end @conditions.freeze end |
Instance Attribute Details
#app ⇒ Object (readonly)
Valid rack application to call if conditions are met
18 19 20 |
# File 'lib/rack/mount/route.rb', line 18 def app @app end |
#conditions ⇒ Object (readonly)
A hash of conditions to match against. Conditions may be expressed as strings or regexps to match against.
22 23 24 |
# File 'lib/rack/mount/route.rb', line 22 def conditions @conditions end |
#defaults ⇒ Object (readonly)
A hash of values that always gets merged into the parameters hash
25 26 27 |
# File 'lib/rack/mount/route.rb', line 25 def defaults @defaults end |
#name ⇒ Object (readonly)
Symbol identifier for the route used with named route generations
28 29 30 |
# File 'lib/rack/mount/route.rb', line 28 def name @name end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
60 61 62 |
# File 'lib/rack/mount/route.rb', line 60 def inspect #:nodoc: "#<#{self.class.name} @app=#{@app.inspect} @conditions=#{@conditions.inspect} @defaults=#{@defaults.inspect} @name=#{@name.inspect}>" end |