From 1c9431753939b9987416debf839d5707efe4dc18 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 14:30:40 -0700 Subject: add a method to `Scope` for getting mapping options Eventually we don't want to expose the "options" hash from scope, only read values from it. Lets start by adding a reader method. --- actionpack/lib/action_dispatch/routing/mapper.rb | 10 ++++++++-- actionpack/test/dispatch/mapper_test.rb | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index bf35a2b960..6e1db3b492 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -62,7 +62,7 @@ module ActionDispatch attr_reader :to, :default_controller, :default_action, :as, :anchor def self.build(scope, set, path, as, controller, default_action, to, via, options) - formatted = options.delete(:format) { scope[:options] && scope[:options][:format] } + formatted = options.delete(:format) { scope.mapping_option(:format) } options = scope[:options].merge(options) if scope[:options] @@ -1543,7 +1543,7 @@ module ActionDispatch option_path = options.delete :path to = options.delete :to via = Mapping.check_via Array(options.delete(:via) { - (@scope[:options] || {})[:via] + @scope.mapping_option(:via) }) path_types = paths.group_by(&:class) @@ -1990,6 +1990,12 @@ module ActionDispatch OPTIONS end + def mapping_option(name) + options = self[:options] + return unless options + options[name] + end + def new(hash) self.class.new hash, self, scope_level end diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index e36f1718ac..9076dab0c0 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -50,7 +50,8 @@ module ActionDispatch def test_mapping_requirements options = { } - m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], options) + scope = Mapper::Scope.new({}) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3