Sha256: a05973aa50a9d802c70164d12a89f134196ff6ddf29875e6da4f8fa625171403

Contents?: true

Size: 734 Bytes

Versions: 12

Compression:

Stored size: 734 Bytes

Contents

module Valle
  class ValidationSetter
    class << self

      ##
      # Adds validator to the klass column depending on its type
      #
      # @param [AbstractAdapter::AbstractColumn] column the column
      # @param [ActiveRecord::Base] klass the AR model class
      #
      def add_validator(column, klass)
        options = {}
        options[:minimum] = column.minimum if column.minimum
        options[:maximum] = column.maximum if column.maximum
        return false unless options.present?

        case column.type
        when :string, :text
          klass.validates column.name, length: options
        when :integer
          klass.validates column.name, numericality: options
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
valle-1.1.2 lib/valle/validation_setter.rb
valle-1.1.1 lib/valle/validation_setter.rb
valle-1.1.0 lib/valle/validation_setter.rb
valle-1.0.1 lib/valle/validation_setter.rb
valle-1.0.0 lib/valle/validation_setter.rb
valle-0.2.3 lib/valle/validation_setter.rb
valle-0.2.2 lib/valle/validation_setter.rb
valle-0.2.1 lib/valle/validation_setter.rb
valle-0.2.0 lib/valle/validation_setter.rb
valle-0.1.0 lib/valle/validation_setter.rb
valle-0.0.3 lib/valle/validation_setter.rb
valle-0.0.2 lib/valle/validation_setter.rb