Class: TFSGraph::Repository::RelatedRepository

Inherits:
TFSGraph::Repository show all
Defined in:
lib/tfs_graph/repository/related_repository.rb

Constant Summary

Constants inherited from TFSGraph::Repository

NotFound

Instance Attribute Summary

Attributes inherited from TFSGraph::Repository

#type

Instance Method Summary collapse

Methods inherited from TFSGraph::Repository

#build, #create, #exists?, #find, #inspect, #rebuild, #related?, #save

Methods included from Extensions

#base_class_name

Constructor Details

#initialize(type) ⇒ RelatedRepository

Returns a new instance of RelatedRepository.



7
8
9
10
# File 'lib/tfs_graph/repository/related_repository.rb', line 7

def initialize(type)
  super
  Related.redis = ServerRegistry.redis
end

Instance Method Details

#delete(obj) ⇒ Object



39
40
41
42
# File 'lib/tfs_graph/repository/related_repository.rb', line 39

def delete(obj)
  obj.db_object.destroy
  super
end

#drop_allObject



32
33
34
35
36
37
# File 'lib/tfs_graph/repository/related_repository.rb', line 32

def drop_all
  flush
  session.keys("*").each do |k|
    session.del k
  end
end

#find_native(id) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/tfs_graph/repository/related_repository.rb', line 12

def find_native(id)
  begin
    Related::Node.find(id)
  rescue Related::NotFound => e
    raise TFSGraph::Repository::NotFound, e.message
  end
end

#flushObject



28
29
30
# File 'lib/tfs_graph/repository/related_repository.rb', line 28

def flush
  # noop
end

#get_nodes(entity, direction, relation, type) ⇒ Object



48
49
50
# File 'lib/tfs_graph/repository/related_repository.rb', line 48

def get_nodes(entity, direction, relation, type)
  get_nodes_for(get_relation(entity, direction, relation), type)
end

#get_nodes_for(relation, type) ⇒ Object



52
53
54
55
56
# File 'lib/tfs_graph/repository/related_repository.rb', line 52

def get_nodes_for(relation, type)
  relation.nodes.map do |node|
    type.repository.rebuild node
  end
end

#get_relation(entity, direction, relation) ⇒ Object



58
59
60
# File 'lib/tfs_graph/repository/related_repository.rb', line 58

def get_relation(entity, direction, relation)
  entity.send(direction.to_sym, relation.to_sym)
end

#relate(relationship, parent, child) ⇒ Object



44
45
46
# File 'lib/tfs_graph/repository/related_repository.rb', line 44

def relate(relationship, parent, child)
  Related::Relationship.create relationship, parent, child
end

#rootObject



20
21
22
# File 'lib/tfs_graph/repository/related_repository.rb', line 20

def root
  Related.root
end

#sessionObject



24
25
26
# File 'lib/tfs_graph/repository/related_repository.rb', line 24

def session
  ServerRegistry.redis
end