Sha256: d0a764d131c54bf84b66193789f5e875016904468dd15f13e3f3e975fb3790c6

Contents?: true

Size: 983 Bytes

Versions: 1

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true

module ActiveFields
  module Field
    class IntegerArray < ActiveFields.config.field_base_class
      store_accessor :options, :min_size, :max_size, :min, :max

      # attribute :min_size, :integer
      # attribute :max_size, :integer
      # attribute :min, :integer
      # attribute :max, :integer

      validates :min_size, comparison: { greater_than_or_equal_to: 0 }, allow_nil: true
      validates :max_size, comparison: { greater_than_or_equal_to: ->(r) { r.min_size || 0 } }, allow_nil: true
      validates :max, comparison: { greater_than_or_equal_to: :min }, allow_nil: true, if: :min

      %i[min_size max_size min max].each do |column|
        define_method(column) do
          Casters::IntegerCaster.new.deserialize(super())
        end

        define_method(:"#{column}=") do |other|
          super(Casters::IntegerCaster.new.serialize(other))
        end
      end

      private

      def set_defaults; end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_fields-0.2.0 app/models/active_fields/field/integer_array.rb