Sha256: fef556254bb44903ab8dd6339d5d5fa8e89d9384efa0541dff5a0c7f1014b877

Contents?: true

Size: 606 Bytes

Versions: 10

Compression:

Stored size: 606 Bytes

Contents

module Doorkeeper
  module Validations
    extend ActiveSupport::Concern

    attr_accessor :error

    def validate
      @error = nil

      self.class.validations.each do |validation|
        @error = validation[:options][:error] unless send("validate_#{validation[:attribute]}")
        break if @error
      end
    end

    def valid?
      validate
      @error.nil?
    end

    module ClassMethods
      def validate(attribute, options = {})
        validations << { attribute: attribute, options: options }
      end

      def validations
        @validations ||= []
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
doorkeeper-4.4.3 lib/doorkeeper/validations.rb
doorkeeper-5.0.0 lib/doorkeeper/validations.rb
doorkeeper-4.4.2 lib/doorkeeper/validations.rb
doorkeeper-4.4.1 lib/doorkeeper/validations.rb
doorkeeper-5.0.0.rc2 lib/doorkeeper/validations.rb
doorkeeper-4.4.0 lib/doorkeeper/validations.rb
doorkeeper-5.0.0.rc1 lib/doorkeeper/validations.rb
doorkeeper-4.3.2 lib/doorkeeper/validations.rb
doorkeeper-4.3.1 lib/doorkeeper/validations.rb
doorkeeper-4.3.0 lib/doorkeeper/validations.rb