Sha256: bd2f33c7e6fbd75b67f9f32d56977cb9a32dc093ad0e66a6b4e004fb9b50bf8e

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module Fakeit
  module App
    class AppBuilder
      def initialize(spec_file, options)
        @config_route = Routes::ConfigRoute.new(options)
        @openapi_route = Routes::OpenapiRoute.new(spec_file)
      end

      def build
        proc do |env|
          request = Rack::Request.new(env)
          base_path = @config_route.options.base_path
          path_info = request.path_info

          if path_info == '/__fakeit_config__'
            config(request)
          elsif path_info.start_with?(base_path)
            openapi(request, path_info[(base_path.length - 1)..])
          elsif "#{path_info}/" == base_path
            openapi(request, '/')
          else
            Fakeit::App::Helpers::ResponseBuilder.not_found
          end
        end
      end

      private

      def config(request)
        @config_route.call(request)
      end

      def openapi(request, path_info)
        request.path_info = path_info
        @openapi_route.call(request, @config_route.options)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fakeit-0.11.0 lib/fakeit/app/app_builder.rb