Sha256: 7c53e1f4a5f63b16a5082ade1560973d193537a6de269e887fcc508f31c6ffdf

Contents?: true

Size: 603 Bytes

Versions: 1

Compression:

Stored size: 603 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

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.6.1 lib/grape/validations/default.rb