Sha256: 0f23237eea72a1e744ac5e6b5df60ba0b2c2e61b809c3dd1941a9e7ae23ebeb3

Contents?: true

Size: 671 Bytes

Versions: 28

Compression:

Stored size: 671 Bytes

Contents

module CustomAttributes
  # This class is only to be extended by types that need length validation
  class Unbounded < FieldType
    def validate_single_value(custom_field, value, customizable = nil)
      errs = super
      value = value.to_s
      if custom_field.min_length && value.length < custom_field.min_length
        errs << ::I18n.t('activerecord.errors.messages.too_short', count: custom_field.min_length)
      end
      if custom_field.max_length && custom_field.max_length > 0 && value.length > custom_field.max_length
        errs << ::I18n.t('activerecord.errors.messages.too_long', count: custom_field.max_length)
      end
      errs
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
create_custom_attributes-0.6.3 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.6.2 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.6.1 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.25 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.24 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.23 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.22 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.21 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.20 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.19 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.18 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.17 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.16 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.15 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.14 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.13 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.12 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.11 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.10 lib/custom_attributes/field_types/unbounded.rb
create_custom_attributes-0.5.9 lib/custom_attributes/field_types/unbounded.rb