class XCActivityLog::SerializedObject

Constants

Attribute

Public Class Methods

attribute(name, type, first_version = 0, first_version_without = 99_999) click to toggle source
# File lib/xcactivitylog/objects.rb, line 6
def self.attribute(name, type, first_version = 0, first_version_without = 99_999)
  attr_reader name
  alias_method "#{name}?", name if type == :boolean
  if type == :time
    define_method(:"#{name}_usec") do
      time = send(name)
      time.to_i * 1_000_000 + time.usec
    end
  end
  attributes << Attribute.new(name, type, first_version, first_version_without).freeze
end
attributes() click to toggle source
# File lib/xcactivitylog/objects.rb, line 18
def self.attributes
  @attributes ||= begin
    SerializedObject == self ? [].freeze : superclass.attributes.dup
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/xcactivitylog/objects.rb, line 30
def ==(other)
  self.class.attributes.reduce(self.class == other.class) do |eq, attr|
    eq && (send(attr.name) == other.send(attr.name))
  end
end
eql?(other) click to toggle source
# File lib/xcactivitylog/objects.rb, line 36
def eql?(other)
  self.class.attributes.reduce(self.class == other.class) do |eq, attr|
    eq && send(attr.name).eql?(other.send(attr.name))
  end
end
hash() click to toggle source
# File lib/xcactivitylog/objects.rb, line 24
def hash
  self.class.attributes.reduce(0x747) do |hash, attr|
    hash ^ send(attr.name).hash
  end
end