app/models/active_fields/field/text.rb in active_fields-0.2.0 vs app/models/active_fields/field/text.rb in active_fields-1.0.0
- old
+ new
@@ -1,14 +1,20 @@
# frozen_string_literal: true
module ActiveFields
module Field
class Text < ActiveFields.config.field_base_class
- store_accessor :options, :required, :min_length, :max_length
+ acts_as_active_field(
+ validator: {
+ class_name: "ActiveFields::Validators::TextValidator",
+ options: -> { { required: required?, min_length: min_length, max_length: max_length } },
+ },
+ caster: {
+ class_name: "ActiveFields::Casters::TextCaster",
+ },
+ )
- # attribute :required, :boolean, default: false
- # attribute :min_length, :integer
- # attribute :max_length, :integer
+ store_accessor :options, :required, :min_length, :max_length
validates :required, exclusion: [nil]
validates :min_length, comparison: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :max_length, comparison: { greater_than_or_equal_to: ->(r) { r.min_length || 0 } }, allow_nil: true