Sha256: 4a0a1c1249ff368f5177bac18f068489a333acd241e060539c56b8a9f1ff2aa5

Contents?: true

Size: 671 Bytes

Versions: 10

Compression:

Stored size: 671 Bytes

Contents

module RailsConnector

  # Adds support for string columns which contain ISO dates
  module DateAttribute
    module ClassMethods
      def date_attribute(*names)
        names.each do |name|
          module_eval %Q!
            def #{name}
              DateAttribute.parse(#{name}_before_type_cast) unless #{name}_before_type_cast.nil?
            end
          !
        end
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    def self.parse(iso_date_time)
      Time.from_iso(iso_date_time).in_time_zone
    rescue ArgumentError
      raise "The value is not a valid ISO date time: #{iso_date_time.inspect}"
    end
  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
infopark_fiona_connector-7.0.1 lib/rails_connector/date_attribute.rb
infopark_fiona_connector-7.0.1.beta2 lib/rails_connector/date_attribute.rb
infopark_fiona_connector-7.0.0 lib/rails_connector/date_attribute.rb
infopark_fiona_connector-6.10.0.beta1 lib/rails_connector/date_attribute.rb
infopark_fiona_connector-6.9.4 lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.9.4 lib/rails_connector/date_attribute.rb
infopark_fiona_connector-6.9.3.1.36404185 lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.9.3.1.36404185 lib/rails_connector/date_attribute.rb
infopark_fiona_connector-6.9.2.1.125136549 lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.9.2.1.125136549 lib/rails_connector/date_attribute.rb