Sha256: 53421aa5e7cc5bcbdedfac275dbaedc9ed15b712f2f3ccb664a03a8833421445

Contents?: true

Size: 1.16 KB

Versions: 18

Compression:

Stored size: 1.16 KB

Contents

module JSONAPIonify::Api
  module Base::AppBuilder

    def self.extended(klass)
      klass.class_eval do
        extend JSONAPIonify::InheritedAttributes
        inherited_array_attribute :middleware
      end
    end

    def use(*args, &block)
      middleware << [args, block]
    end

    def call(env)
      app.call(env)
    end

    private

    def app
      api = self
      Rack::Builder.new do
        use Rack::ShowExceptions
        use Rack::CommonLogger
        use Base::Reloader unless ENV['RACK_ENV'] == 'production'
        map "/docs" do
          run ->(env) {
            request = JSONAPIonify::Api::Server::Request.new env
            if request.path_info.present?
              return [301, { 'location' => request.path.chomp(request.path_info) }, []]
            end
            response = Rack::Response.new
            response.write api.documentation_output(request)
            response.finish
          }
        end
        map "/" do
          use Rack::MethodOverride
          api.middleware.each do |args, block|
            use *args, &block
          end
          run JSONAPIonify::Api::Server.new(api)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
jsonapionify-0.12.2 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.12.1 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.12.0 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.11 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.10 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.9 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.8 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.7 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.6 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.5 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.11.0 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.10.2 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.10.1 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.10.0 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.9.3 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.9.2 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.9.1 lib/jsonapionify/api/base/app_builder.rb
jsonapionify-0.9.0 lib/jsonapionify/api/base/app_builder.rb