diff options
author | Jose and Yehuda <wycats@gmail.com> | 2012-04-25 16:06:20 -0500 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2012-04-25 16:07:17 -0500 |
commit | 6acebb38bc0637bc05c19d87f8767f16ce79189b (patch) | |
tree | e37fa39f516e16c1d36e3b5202e9231c56aa4305 /actionpack/lib/action_dispatch/routing/mapper.rb | |
parent | 3c100cfe8ed5a875b0bbdc8fa4e8f2b0cbf78676 (diff) | |
download | rails-6acebb38bc0637bc05c19d87f8767f16ce79189b.tar.gz rails-6acebb38bc0637bc05c19d87f8767f16ce79189b.tar.bz2 rails-6acebb38bc0637bc05c19d87f8767f16ce79189b.zip |
Allow loading external route files from the router
This feature enables the ability to load an
external routes file from the router via:
draw :filename
External routes files go in +config/routes+. This
feature works in both engines and applications.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index fdc0bfb686..716e2d2271 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1305,6 +1305,21 @@ module ActionDispatch parent_resource.instance_of?(Resource) && @scope[:shallow] end + def draw(name) + path = @draw_paths.find do |path| + path.join("#{name}.rb").file? + end + + unless path + msg = "Your router tried to #draw the external file #{name}.rb,\n" \ + "but the file was not found in:\n\n" + msg += @draw_paths.map { |path| " * #{path}" }.join("\n") + raise msg + end + + instance_eval(path.join("#{name}.rb").read) + end + # match 'path' => 'controller#action' # match 'path', to: 'controller#action' # match 'path', 'otherpath', on: :member, via: :get @@ -1554,6 +1569,7 @@ module ActionDispatch def initialize(set) #:nodoc: @set = set + @draw_paths = set.draw_paths @scope = { :path_names => @set.resources_path_names } end |