Class: Rack::Mount::Route

Inherits:
Object
  • Object
show all
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

Attributes included from Rack::Mount::Recognition::Route

#named_captures

Instance Method Summary collapse

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

#recognize

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

#appObject (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

#conditionsObject (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

#defaultsObject (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

#nameObject (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

#inspectObject

: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