Sha256: 92b32175a0c4a3c0c3b2576b8f305a8aa40060763f5acd38f617c81b30f5718f

Contents?: true

Size: 734 Bytes

Versions: 11

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

module Grape
  module Validations
    module Validators
      class SameAsValidator < Base
        def validate_param!(attr_name, params)
          confirmation = options_key?(:value) ? @option[:value] : @option
          return if params[attr_name] == params[confirmation]

          raise Grape::Exceptions::Validation.new(
            params: [@scope.full_name(attr_name)],
            message: build_message
          )
        end

        private

        def build_message
          if options_key?(:message)
            @option[:message]
          else
            format I18n.t(:same_as, scope: 'grape.errors.messages'), parameter: @option
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
grape-2.2.0 lib/grape/validations/validators/same_as_validator.rb
grape-2.1.3 lib/grape/validations/validators/same_as_validator.rb
grape-2.1.2 lib/grape/validations/validators/same_as_validator.rb
grape-2.1.1 lib/grape/validations/validators/same_as_validator.rb
grape-2.1.0 lib/grape/validations/validators/same_as_validator.rb
grape-2.0.0 lib/grape/validations/validators/same_as_validator.rb
grape-1.8.0 lib/grape/validations/validators/same_as_validator.rb
grape-1.7.1 lib/grape/validations/validators/same_as_validator.rb
grape-1.7.0 lib/grape/validations/validators/same_as_validator.rb
grape-1.6.2 lib/grape/validations/validators/same_as.rb
grape-1.6.1 lib/grape/validations/validators/same_as_validator.rb