Skip to content

Commit

Permalink
disconnect the constraints method from the options and scope hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jun 3, 2014
1 parent 4bc441c commit e975b7d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ def initialize(scope, path, options)
ast = path_ast path
path_params = path_params ast
@options = normalize_options!(options, formatted, path_params, ast)
normalize_requirements!(path_params, formatted)

normalize_conditions!(path_params, path, ast, via)

constraints = constraints(options[:constraints], scope[:constraints])
normalize_requirements!(path_params, formatted, constraints)

normalize_conditions!(path_params, path, ast, via, constraints)
normalize_defaults!(formatted)
end

Expand Down Expand Up @@ -138,7 +141,7 @@ def normalize_options!(options, formatted, path_params, path_ast)
end
end

def normalize_requirements!(path_params, formatted)
def normalize_requirements!(path_params, formatted, constraints)
constraints.each do |key, requirement|
next unless path_params.include?(key) || key == :controller
verify_regexp_requirement(requirement) if requirement.is_a?(Regexp)
Expand Down Expand Up @@ -197,7 +200,7 @@ def verify_callable_constraint(callable_constraint)
end
end

def normalize_conditions!(path_params, path, ast, via)
def normalize_conditions!(path_params, path, ast, via, constraints)
@conditions[:path_info] = path
@conditions[:parsed_path_info] = ast

Expand Down Expand Up @@ -308,16 +311,16 @@ def blocks
end
end

def constraints
@constraints ||= {}.tap do |constraints|
constraints.merge!(scope[:constraints]) if scope[:constraints]
def constraints(option_constraints, scope_constraints)
constraints = {}
constraints.merge!(scope_constraints) if scope_constraints

options.except(*IGNORE_OPTIONS).each do |key, option|
constraints[key] = option if Regexp === option
end

constraints.merge!(options[:constraints]) if options[:constraints].is_a?(Hash)
options.except(*IGNORE_OPTIONS).each do |key, option|
constraints[key] = option if Regexp === option
end

constraints.merge!(option_constraints) if option_constraints.is_a?(Hash)
constraints
end

def path_params(ast)
Expand Down

0 comments on commit e975b7d

Please sign in to comment.