Class: TFSGraph::PersistableEntity

Inherits:
Entity
  • Object
show all
Includes:
Comparable, Extensions
Defined in:
lib/tfs_graph/persistable_entity.rb

Direct Known Subclasses

Branch, Changeset, Project

Constant Summary collapse

NotPersisted =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions

#base_class_name

Methods inherited from Entity

inherited, #schema

Constructor Details

#initialize(repo, args) ⇒ PersistableEntity

Returns a new instance of PersistableEntity.



17
18
19
20
# File 'lib/tfs_graph/persistable_entity.rb', line 17

def initialize(repo, args)
  @repo = repo
  super args
end

Instance Attribute Details

#db_objectObject

Returns the value of attribute db_object.



11
12
13
# File 'lib/tfs_graph/persistable_entity.rb', line 11

def db_object
  @db_object
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/tfs_graph/persistable_entity.rb', line 11

def id
  @id
end

Class Method Details

.repositoryObject



13
14
15
# File 'lib/tfs_graph/persistable_entity.rb', line 13

def self.repository
  TFSGraph::RepositoryRegistry.instance.send "#{base_class_name.downcase}_repository"
end

Instance Method Details

#delete!Object



30
31
32
33
34
35
# File 'lib/tfs_graph/persistable_entity.rb', line 30

def delete!
  @repo.delete(self)

  @db_object = nil
  @id = nil
end

#persist(id, db_object) ⇒ Object



37
38
39
40
41
42
# File 'lib/tfs_graph/persistable_entity.rb', line 37

def persist(id, db_object)
  @id ||= id
  @db_object = db_object

  self
end

#persisted?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/tfs_graph/persistable_entity.rb', line 22

def persisted?
  !db_object.nil?
end

#save!Object



26
27
28
# File 'lib/tfs_graph/persistable_entity.rb', line 26

def save!
  @repo.save(self)
end

#to_hashObject



53
54
55
56
57
58
# File 'lib/tfs_graph/persistable_entity.rb', line 53

def to_hash
  hash = super
  hash[:id] = id

  hash
end