Sha256: c28e9062b27a2fcebd9d1730757d98a4e4325d13a21a66c7ffa1ac104818ae8b

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

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

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

      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].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

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

        define_method(:"#{column}=") do |other|
          super(Casters::DateCaster.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/date_array.rb