Sha256: e72afa6a93e2c849930e35aab9624d628afb41ce4b4b5c29be6a640869562e03

Contents?: true

Size: 681 Bytes

Versions: 27

Compression:

Stored size: 681 Bytes

Contents

module RailsConnector

  # Adds support for string columns which contain ISO dates
  module DateAttribute #:nodoc: all
    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).localtime
    rescue ArgumentError
      raise "The value is not a valid ISO date time: #{iso_date_time.inspect}"
    end
  end

end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
infopark_cloud_connector-6.8.0.beta.200.744.99f67fc lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.8.0.beta.200.720.44fbabd lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.8.0.beta.200.713.e5c3150 lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.8.0.beta.200.681.7c84f4a lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.8.0.beta.200.663.ceecdee lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.8.0.beta.200.650.7c93155 lib/rails_connector/date_attribute.rb
infopark_cloud_connector-6.8.0.beta.200.621.4c8e1b0 lib/rails_connector/date_attribute.rb