Sha256: 826ca87a330ba7206fa67b80b0bd626821d33d2ad2bea734289722eac5d56978

Contents?: true

Size: 821 Bytes

Versions: 3

Compression:

Stored size: 821 Bytes

Contents

# frozen_string_literal: true

module PriceHubble
  module Concern
    module Attributes
      # A separated date array typed attribute helper.
      module DateArray
        extend ActiveSupport::Concern

        class_methods do
          # Register a date array attribute (only sanitization).
          #
          # @param name [Symbol, String] the name of the attribute
          # @param _args [Hash{Symbol => Mixed}] additional options
          def typed_attr_date_array(name, **_args)
            class_eval <<-RUBY, __FILE__, __LINE__ + 1
              def sanitize_attr_#{name}
                return if @#{name}.nil?
                @#{name}.map do |date|
                  date.strftime('%Y-%m-%d')
                end
              end
            RUBY
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pricehubble-1.6.0 lib/price_hubble/entity/concern/attributes/date_array.rb
pricehubble-1.5.1 lib/price_hubble/entity/concern/attributes/date_array.rb
pricehubble-1.5.0 lib/price_hubble/entity/concern/attributes/date_array.rb