Sha256: a60253bcf9664ab63956d83d293e987ec4671a88723d668e25e4fe1360c681a4

Contents?: true

Size: 630 Bytes

Versions: 5

Compression:

Stored size: 630 Bytes

Contents

module Grape
  module Validations
    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,
              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

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/validations/validators/same_as.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/validations/validators/same_as.rb
grape-1.2.5 lib/grape/validations/validators/same_as.rb
grape-1.2.4 lib/grape/validations/validators/same_as.rb
grape-1.2.3 lib/grape/validations/validators/same_as.rb