Class: ActionDispatch::Routing::Mapper::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/action_dispatch/routing/mapper.rb

Overview

:nodoc:

Constant Summary collapse

ANCHOR_CHARACTERS_REGEX =
%r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, set, path, defaults, as, options) ⇒ Mapping

Returns a new instance of Mapping.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/action_dispatch/routing/mapper.rb', line 81

def initialize(scope, set, path, defaults, as, options)
  @requirements, @conditions = {}, {}
  @defaults = defaults
  @set = set

  @to                 = options.delete :to
  @default_controller = options.delete(:controller) || scope[:controller]
  @default_action     = options.delete(:action) || scope[:action]
  @as                 = as
  @anchor             = options.delete :anchor

  formatted = options.delete :format
  via = Array(options.delete(:via) { [] })
  options_constraints = options.delete :constraints

  path = normalize_path! path, formatted
  ast  = path_ast path
  path_params = path_params ast

  options = normalize_options!(options, formatted, path_params, ast, scope[:module])


  split_constraints(path_params, scope[:constraints]) if scope[:constraints]
  constraints = constraints(options, path_params)

  split_constraints path_params, constraints

  @blocks = blocks(options_constraints, scope[:blocks])

  if options_constraints.is_a?(Hash)
    split_constraints path_params, options_constraints
    options_constraints.each do |key, default|
      if URL_OPTIONS.include?(key) && (String === default || Fixnum === default)
        @defaults[key] ||= default
      end
    end
  end

  normalize_format!(formatted)

  @conditions[:path_info] = path
  @conditions[:parsed_path_info] = ast

  add_request_method(via, @conditions)
  normalize_defaults!(options)
end

Instance Attribute Details

#anchorObject (readonly)

Returns the value of attribute anchor.



65
66
67
# File 'lib/action_dispatch/routing/mapper.rb', line 65

def anchor
  @anchor
end

#asObject (readonly)

Returns the value of attribute as.



65
66
67
# File 'lib/action_dispatch/routing/mapper.rb', line 65

def as
  @as
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



64
65
66
# File 'lib/action_dispatch/routing/mapper.rb', line 64

def conditions
  @conditions
end

#default_actionObject (readonly)

Returns the value of attribute default_action.



65
66
67
# File 'lib/action_dispatch/routing/mapper.rb', line 65

def default_action
  @default_action
end

#default_controllerObject (readonly)

Returns the value of attribute default_controller.



65
66
67
# File 'lib/action_dispatch/routing/mapper.rb', line 65

def default_controller
  @default_controller
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



64
65
66
# File 'lib/action_dispatch/routing/mapper.rb', line 64

def defaults
  @defaults
end

#requirementsObject (readonly)

Returns the value of attribute requirements.



64
65
66
# File 'lib/action_dispatch/routing/mapper.rb', line 64

def requirements
  @requirements
end

#toObject (readonly)

Returns the value of attribute to.



65
66
67
# File 'lib/action_dispatch/routing/mapper.rb', line 65

def to
  @to
end

Class Method Details

.build(scope, set, path, as, options) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/action_dispatch/routing/mapper.rb', line 67

def self.build(scope, set, path, as, options)
  options = scope[:options].merge(options) if scope[:options]

  options.delete :only
  options.delete :except
  options.delete :shallow_path
  options.delete :shallow_prefix
  options.delete :shallow

  defaults = (scope[:defaults] || {}).merge options.delete(:defaults) || {}

  new scope, set, path, defaults, as, options
end

Instance Method Details

#to_routeObject



128
129
130
# File 'lib/action_dispatch/routing/mapper.rb', line 128

def to_route
  [ app(@blocks), conditions, requirements, defaults, as, anchor ]
end