Class: TFSGraph::Repository
- Inherits:
-
Object
- Object
- TFSGraph::Repository
show all
- Includes:
- Extensions
- Defined in:
- lib/tfs_graph/repository.rb,
lib/tfs_graph/repository/neo4j_repository.rb,
lib/tfs_graph/repository/related_repository.rb
Defined Under Namespace
Classes: Neo4jRepository, RelatedRepository
Constant Summary
collapse
- NotFound =
Class.new(RuntimeError)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Extensions
#base_class_name
Constructor Details
Returns a new instance of Repository.
17
18
19
20
21
22
23
24
|
# File 'lib/tfs_graph/repository.rb', line 17
def initialize(type)
@type = type
add_behavior self, constantize("TFSGraph::Behaviors::#{self.base_class_name}::#{type.base_class_name}")
ServerRegistry.server(self)
end
|
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
13
14
15
|
# File 'lib/tfs_graph/repository.rb', line 13
def type
@type
end
|
Instance Method Details
#build(args = {}) ⇒ Object
53
54
55
|
# File 'lib/tfs_graph/repository.rb', line 53
def build(args={})
@type.new self, args
end
|
#create(args) ⇒ Object
64
65
66
67
|
# File 'lib/tfs_graph/repository.rb', line 64
def create(args)
object = build(args)
save(object)
end
|
#delete(obj) ⇒ Object
48
49
50
51
|
# File 'lib/tfs_graph/repository.rb', line 48
def delete(obj)
obj.db_object = nil
obj.id = nil
end
|
#exists?(id) ⇒ Boolean
30
31
32
33
34
35
36
37
|
# File 'lib/tfs_graph/repository.rb', line 30
def exists?(id)
begin
find_native(id)
true
rescue NotFound
false
end
end
|
#find(id) ⇒ Object
26
27
28
|
# File 'lib/tfs_graph/repository.rb', line 26
def find(id)
rebuild find_native(id)
end
|
#inspect ⇒ Object
69
70
71
|
# File 'lib/tfs_graph/repository.rb', line 69
def inspect
type
end
|
#rebuild(db_object) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/tfs_graph/repository.rb', line 57
def rebuild(db_object)
attributes = HashWithIndifferentAccess.new db_object.attributes
obj = build attributes
obj.persist get_id(db_object), db_object
end
|
39
40
41
|
# File 'lib/tfs_graph/repository.rb', line 39
def related?(node1, node2, type)
node1.rels(dir: :outgoing, between: node2, type: type).any?
end
|
#save(object) ⇒ Object
43
44
45
46
|
# File 'lib/tfs_graph/repository.rb', line 43
def save(object)
db_object = object.persisted? ? update(object) : persist(object)
object.persist get_id(db_object), db_object
end
|