Object
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.
# File lib/rack/mount/route.rb, line 27 27: def initialize(app, conditions, defaults, name) 28: unless app.respond_to?(:call) 29: raise ArgumentError, 'app must be a valid rack application' ' and respond to call' 30: end 31: @app = app 32: 33: @name = name ? name.to_sym : nil 34: @defaults = (defaults || {}).freeze 35: 36: @conditions = {} 37: 38: conditions.each do |method, pattern| 39: next unless method && pattern 40: 41: pattern = Regexp.compile("\\A#{Regexp.escape(pattern)}\\Z") if pattern.is_a?(String) 42: 43: if pattern.is_a?(Regexp) 44: pattern = Utils.normalize_extended_expression(pattern) 45: pattern = RegexpWithNamedGroups.new(pattern) 46: pattern.extend(GeneratableRegexp::InstanceMethods) 47: pattern.defaults = @defaults 48: end 49: 50: @conditions[method] = pattern.freeze 51: end 52: 53: @named_captures = {} 54: @conditions.map { |method, condition| 55: next unless condition.respond_to?(:named_captures) 56: @named_captures[method] = condition.named_captures.inject({}) { |named_captures, (k, v)| 57: named_captures[k.to_sym] = v.last - 1 58: named_captures 59: }.freeze 60: } 61: @named_captures.freeze 62: 63: @has_significant_params = @conditions.any? { |method, condition| 64: (condition.respond_to?(:required_params) && condition.required_params.any?) || 65: (condition.respond_to?(:required_defaults) && condition.required_defaults.any?) 66: } 67: 68: if @conditions.has_key?(:path_info) && 69: !Utils.regexp_anchored?(@conditions[:path_info]) 70: @prefix = true 71: @app = Prefix.new(@app) 72: else 73: @prefix = false 74: end 75: 76: @conditions.freeze 77: end
# File lib/rack/mount/route.rb, line 99 99: def generate(method, params = {}, recall = {}, options = {}) 100: if method.nil? 101: result = @conditions.inject({}) { |h, (m, condition)| 102: if condition.respond_to?(:generate) 103: h[m] = condition.generate(params, recall, options) 104: end 105: h 106: } 107: return nil if result.values.compact.empty? 108: else 109: if condition = @conditions[method] 110: if condition.respond_to?(:generate) 111: result = condition.generate(params, recall, options) 112: end 113: end 114: end 115: 116: if result 117: @defaults.each do |key, value| 118: params.delete(key) if params[key] == value 119: end 120: end 121: 122: result 123: end
# File lib/rack/mount/route.rb, line 85 85: def generation_keys 86: @conditions.inject({}) { |keys, (method, condition)| 87: if condition.respond_to?(:required_defaults) 88: keys.merge!(condition.required_defaults) 89: else 90: keys 91: end 92: } 93: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.