From 319106d09c0ec2daf8b5345f525f1c97b6368ce2 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Sun, 22 Feb 2009 19:23:04 +0000 Subject: Metal can now line in plugins under app/metal [#2045 state:committed] Signed-off-by: David Heinemeier Hansson --- railties/lib/rails/rack/metal.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails/rack/metal.rb') diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index b185227234..8dac992ef2 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -6,14 +6,17 @@ module Rails NotFoundResponse = [404, {}, []].freeze NotFound = lambda { NotFoundResponse } + cattr_accessor :metal_paths + self.metal_paths = ["#{Rails.root}/app/metal"] + def self.metals - base = "#{Rails.root}/app/metal" - matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/ + matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/ + metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } - Dir["#{base}/**/*.rb"].sort.map do |file| - file.sub!(matcher, '\1') - require file - file.classify.constantize + Dir[*metal_glob].sort.map do |file| + path = file.match(matcher)[1] + require path + path.classify.constantize end end -- cgit v1.2.3 From 4d4d2c3896ed5a5d74da833c5c3132f406f4eab7 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Tue, 3 Mar 2009 12:39:19 -0600 Subject: Enhanced Rails Metal - the load order of metals can now be configured [#2057 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/rails/rack/metal.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails/rack/metal.rb') diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index 8dac992ef2..bce59f4c78 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -8,16 +8,26 @@ module Rails cattr_accessor :metal_paths self.metal_paths = ["#{Rails.root}/app/metal"] + cattr_accessor :requested_metals def self.metals matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/ metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } + all_metals = {} Dir[*metal_glob].sort.map do |file| - path = file.match(matcher)[1] - require path - path.classify.constantize + file = file.match(matcher)[1] + all_metals[file.classify] = file end + + load_list = requested_metals || all_metals.keys + + load_list.map do |requested_metal| + if metal = all_metals[requested_metal] + require metal + requested_metal.constantize + end + end.compact end def initialize(app) -- cgit v1.2.3 From e97180c273ada9b252ddf42d340d2947a509cb26 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Thu, 5 Mar 2009 18:50:52 -0600 Subject: Ensure that loading metals from the main app and engines works on older Ruby versions [#2143 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/rails/rack/metal.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails/rack/metal.rb') diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index bce59f4c78..78b8a01449 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -15,9 +15,11 @@ module Rails metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } all_metals = {} - Dir[*metal_glob].sort.map do |file| - file = file.match(matcher)[1] - all_metals[file.classify] = file + metal_glob.each do |glob| + Dir[glob].sort.map do |file| + file = file.match(matcher)[1] + all_metals[file.classify] = file + end end load_list = requested_metals || all_metals.keys -- cgit v1.2.3