Sha256: 17d8ef4778ac3d933a811d00a6d32524d0a649fb307ed23a71574e5c595126d6

Contents?: true

Size: 604 Bytes

Versions: 2

Compression:

Stored size: 604 Bytes

Contents

module Grape
  module Validations
    class DefaultValidator < Validator
      def initialize(attrs, options, required, scope)
        @default = options
        super
      end

      def validate_param!(attr_name, params)
        params[attr_name] = @default unless params.has_key?(attr_name)
      end

      def validate!(params)
        params = AttributesIterator.new(self, @scope, params)
        params.each do |resource_params, attr_name|
          if resource_params[attr_name].nil?
            validate_param!(attr_name, resource_params)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-0.6.0 lib/grape/validations/default.rb
grape-0.5.0 lib/grape/validations/default.rb