aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/rack/metal.rb
blob: 1df31a1594286baa9ef9739b58cc764e5edb7476 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'rails/rack/cascade'

module Rails
  module Rack
    module Metal
      NotFoundResponse = [404, {}, []].freeze
      NotFound = lambda { NotFoundResponse }

      class << self
        def new(app)
          Cascade.new(builtins + [app])
        end

        def builtins
          base = "#{Rails.root}/app/metal"
          matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/

          Dir["#{base}/**/*.rb"].sort.map do |file|
            file.sub!(matcher, '\1')
            require file
            file.classify.constantize
          end
        end
      end
    end
  end
end