Sha256: 7b8f6b400d0afa7386b9473ece6595c227178ed7a6aed46905e34434bb897470

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module MassiveRecord
  module ORM

    #
    # Class to hold one raw data, and some meta data for that value.
    # As of writing this the meta data is when cell which the data
    # originates from was last written to (created_at).
    #
    class RawData
      attr_reader :value, :created_at


      class << self
        def new_with_data_from(object)
          send("new_with_data_from_#{object.class.to_s.demodulize.underscore}", object)
        end


        private

        def new_with_data_from_cell(cell)
          new(value: cell.value, created_at: cell.created_at)
        end
      end



      def initialize(attributes)
        @value = attributes[:value]
        @created_at = attributes[:created_at]
      end

      delegate :inspect, :to_s, :to => :value


      def ==(other)
        other.equal?(self) ||
          other.instance_of?(self.class) && value == other.value && created_at == other.created_at
      end
      alias_method :eql?, :==

      def hash
        [id, created_at].hash
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
massive_record-0.2.2 lib/massive_record/orm/raw_data.rb
massive_record-0.2.2.rc2 lib/massive_record/orm/raw_data.rb
massive_record-0.2.2.rc1 lib/massive_record/orm/raw_data.rb