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

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

Overview

:nodoc:

Constant Summary collapse

ANCHOR_CHARACTERS_REGEX =
%r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
OPTIONAL_FORMAT_REGEX =
%r{(?:\(\.:format\)+|\.:format|/)\Z}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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


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
127
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 82

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 || Integer === 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


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

def anchor
  @anchor
end

#asObject (readonly)

Returns the value of attribute as


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

def as
  @as
end

#conditionsObject (readonly)

Returns the value of attribute conditions


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

def conditions
  @conditions
end

#default_actionObject (readonly)

Returns the value of attribute default_action


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

def default_action
  @default_action
end

#default_controllerObject (readonly)

Returns the value of attribute default_controller


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

def default_controller
  @default_controller
end

#defaultsObject (readonly)

Returns the value of attribute defaults


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

def defaults
  @defaults
end

#requirementsObject (readonly)

Returns the value of attribute requirements


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

def requirements
  @requirements
end

#toObject (readonly)

Returns the value of attribute to


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

def to
  @to
end

Class Method Details

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


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

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


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

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