Sha256: 889c46a4674703bc74ecb5dea97e26a08e43c5b8beaf22dc4ff28ee90a001aad

Contents?: true

Size: 774 Bytes

Versions: 14

Compression:

Stored size: 774 Bytes

Contents

module CustomFields
  module Types
    module Date

      extend ActiveSupport::Concern

      included do
        register_type :date, ::Date
      end

      module InstanceMethods

        def apply_date_type(klass)

          klass.class_eval <<-EOF
            def #{self.safe_alias}
              self.#{self._name}.strftime(I18n.t('date.formats.default')) rescue nil
            end

            def #{self.safe_alias}=(value)
              if value.is_a?(::String) && !value.blank?
                date = ::Date._strptime(value, I18n.t('date.formats.default'))
                value = ::Date.new(date[:year], date[:mon], date[:mday])
              end

              self.#{self._name} = value
            end
          EOF

        end

      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
custom_fields-1.0.0.beta.19 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.18 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.17 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.16 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.15 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.14 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.13 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.12 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.11 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.10 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.9 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.8 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.7 lib/custom_fields/types/date.rb
custom_fields-1.0.0.beta.6 lib/custom_fields/types/date.rb