Class: Rails::Rack::Metal

Inherits:
Object show all
Defined in:
lib/rails/rack/metal.rb

Constant Summary collapse

NotFoundResponse =
[404, {}, []].freeze
NotFound =
lambda { NotFoundResponse }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Metal

Returns a new instance of Metal.



35
36
37
38
39
40
# File 'lib/rails/rack/metal.rb', line 35

def initialize(app)
  @app = app
  @metals = ActiveSupport::OrderedHash.new
  self.class.metals.each { |app| @metals[app] = true }
  freeze
end

Class Method Details

.metalsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails/rack/metal.rb', line 13

def self.metals
  matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/
  metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" }
  all_metals = {}

  metal_glob.each do |glob|
    Dir[glob].sort.map do |file|
      file = file.match(matcher)[1]
      all_metals[file.camelize] = file
    end
  end

  load_list = requested_metals || all_metals.keys

  load_list.map do |requested_metal|
    if metal = all_metals[requested_metal]
      require_dependency metal
      requested_metal.constantize
    end
  end.compact
end

Instance Method Details

#call(env) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rails/rack/metal.rb', line 42

def call(env)
  @metals.keys.each do |app|
    result = app.call(env)
    return result unless result[0].to_i == 404
  end
  @app.call(env)
end