Sha256: 37791dccb6008cbf7c8a3b99b07a5682700a98307760eb3915b57dff8c3f7c21

Contents?: true

Size: 1.01 KB

Versions: 20

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

module Hyperdrive
  module Middleware
    class RequiredParams
      def initialize(app)
        @app = app
      end

      def call(env)
        @env = env
        if %w(GET HEAD).include? env['REQUEST_METHOD']
          check_required_params(env['hyperdrive.resource'].filters)
        elsif %W(POST PUT PATCH DELETE).include? env['REQUEST_METHOD']
          check_required_params(env['hyperdrive.resource'].params)
        end
        @app.call(env)
      end

      def check_required_params(params)
        params.each do |param, options|
          if @env['hyperdrive.resource'].required?(param, @env['REQUEST_METHOD'])
            if @env['hyperdrive.params'].key?(param)
              if @env['hyperdrive.params'][param] == ''
                raise Errors::MissingRequiredParam.new(param, @env['REQUEST_METHOD'])
              end
            else
              raise Errors::MissingRequiredParam.new(param, @env['REQUEST_METHOD'])
            end
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.24 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.23 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.22 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.21 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.20 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.19 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.18 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.17 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.16 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.15 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.14 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.13 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.12 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.11 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.10 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.9 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.8 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.7 lib/hyperdrive/middleware/required_params.rb
hyperdrive-0.0.6 lib/hyperdrive/middleware/required_params.rb