class TFSGraph::Repository::RelatedRepository

Public Class Methods

new(type) click to toggle source
Calls superclass method TFSGraph::Repository::new
# File lib/tfs_graph/repository/related_repository.rb, line 7
def initialize(type)
  super
  Related.redis = ServerRegistry.redis
end

Public Instance Methods

delete(obj) click to toggle source
Calls superclass method TFSGraph::Repository#delete
# File lib/tfs_graph/repository/related_repository.rb, line 39
def delete(obj)
  obj.db_object.destroy
  super
end
drop_all() click to toggle source
# 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) click to toggle source
# 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
flush() click to toggle source
# File lib/tfs_graph/repository/related_repository.rb, line 28
def flush
  # noop
end
get_nodes(entity, direction, relation, type) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/tfs_graph/repository/related_repository.rb, line 44
def relate(relationship, parent, child)
  Related::Relationship.create relationship, parent, child
end
root() click to toggle source
# File lib/tfs_graph/repository/related_repository.rb, line 20
def root
  Related.root
end
session() click to toggle source
# File lib/tfs_graph/repository/related_repository.rb, line 24
def session
  ServerRegistry.redis
end

Private Instance Methods

get_id(object) click to toggle source
# File lib/tfs_graph/repository/related_repository.rb, line 83
def get_id(object)
  return 0 if object.nil?
  object.id
end
persist(object) click to toggle source

create the DB object

# File lib/tfs_graph/repository/related_repository.rb, line 67
def persist(object)
  Related::Node.create(object.to_hash)
end
update(object) click to toggle source

update the DB object

# File lib/tfs_graph/repository/related_repository.rb, line 72
def update(object)
  db_object = object.db_object

  object.attributes.each do |key, value|
    db_object.write_attribute key, value
  end

  db_object.save
  db_object
end