Class: VCSToolkit::Objects::Object

Inherits:
Object
  • Object
show all
Extended by:
Serializable
Includes:
Utils::HashableObject
Defined in:
lib/vcs_toolkit/objects/object.rb

Direct Known Subclasses

Blob, Commit, Label, Tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Serializable

from_hash, serialize_on

Methods included from Utils::HashableObject

included

Constructor Details

#initialize(id: nil, object_type: :object, named: false, verify_object_id: true, **context) ⇒ Object

Returns a new instance of Object.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vcs_toolkit/objects/object.rb', line 14

def initialize(id:               nil,
               object_type:      :object,
               named:            false,
               verify_object_id: true,
               **context)
  @object_type = object_type.to_sym
  @named       = named

  if id
    @id = id
    raise InvalidObjectError, 'Invalid id' if verify_object_id and not named? and not id_valid?
  else
    raise InvalidObjectError, 'Named objects should always specify an id' if named?
    @id = generate_id
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/vcs_toolkit/objects/object.rb', line 11

def id
  @id
end

#object_typeObject (readonly)

Returns the value of attribute object_type.



11
12
13
# File 'lib/vcs_toolkit/objects/object.rb', line 11

def object_type
  @object_type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



35
36
37
# File 'lib/vcs_toolkit/objects/object.rb', line 35

def ==(other)
  id == other.id
end

#hashObject



41
42
43
# File 'lib/vcs_toolkit/objects/object.rb', line 41

def hash
  id.hash
end

#named?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/vcs_toolkit/objects/object.rb', line 31

def named?
  @named
end