Class: XCActivityLog::SerializedObject

Inherits:
Object
  • Object
show all
Defined in:
lib/xcactivitylog/objects.rb

Defined Under Namespace

Classes: Attribute

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attribute(name, type, first_version = 0, first_version_without = 99_999) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# 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

.attributesObject



18
19
20
21
22
# File 'lib/xcactivitylog/objects.rb', line 18

def self.attributes
  @attributes ||= begin
    SerializedObject == self ? [].freeze : superclass.attributes.dup
  end
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
33
34
# 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) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# 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

#hashObject



24
25
26
27
28
# File 'lib/xcactivitylog/objects.rb', line 24

def hash
  self.class.attributes.reduce(0x747) do |hash, attr|
    hash ^ send(attr.name).hash
  end
end