Module: N4j::Node

Extended by:
ActiveSupport::Concern
Included in:
GenericNode
Defined in:
lib/n4j/node.rb

Defined Under Namespace

Modules: AutoRelate, ClassMethods, Index

Instance Method Summary collapse

Instance Method Details

#body_hashObject



43
44
45
# File 'lib/n4j/node.rb', line 43

def body_hash
  data
end

#clear_new_relationships!Object



89
90
91
# File 'lib/n4j/node.rb', line 89

def clear_new_relationships!
  @new_relationships = []
end

#connected_unsavedObject



51
52
53
# File 'lib/n4j/node.rb', line 51

def connected_unsaved
  new_relationships
end

#create_pathObject



39
40
41
# File 'lib/n4j/node.rb', line 39

def create_path
  '/node'
end

#cypher(opts = {}) ⇒ Object



80
81
82
83
# File 'lib/n4j/node.rb', line 80

def cypher(opts = {})
  defaults = {:start => self, :instantiate_with => self.class}
  N4j::Cypher.new(defaults.merge(opts))
end

#dependentObject



47
48
49
# File 'lib/n4j/node.rb', line 47

def dependent
  relationships
end

#entity_typeObject



70
71
72
# File 'lib/n4j/node.rb', line 70

def entity_type
  'node'
end

#initialize(hsh) ⇒ Object



32
33
34
35
36
37
# File 'lib/n4j/node.rb', line 32

def initialize(hsh)
  super(hsh)
  unless N4j.neo4j_hash?(hsh)
    self.data = HashWithIndifferentAccess.new.merge(hsh)
  end
end

#new_relationshipsObject



85
86
87
# File 'lib/n4j/node.rb', line 85

def new_relationships
  @new_relationships ||= []
end

#post_saveObject



55
56
57
# File 'lib/n4j/node.rb', line 55

def post_save
  clear_new_relationships!
end

#relationships(direction = 'all_relationships', types = [], clear_cache = false) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/n4j/node.rb', line 59

def relationships(direction = 'all_relationships', types = [], clear_cache = false)
  @relationship_cache ||= {}
  if persisted?
    path = from_neo4j_relative[direction] + '/' + [types].flatten.join('&')
    @relationship_cache.delete(path) if clear_cache
    @relationship_cache[path] ||= GenericRelationship.find_by_node_path(path)
  else
    []
  end
end

#traverse(opts = {}) ⇒ Object



74
75
76
77
78
# File 'lib/n4j/node.rb', line 74

def traverse(opts = {})
  # Started this approach, stoppedto investigate Cypher
  defaults = {:start => path, :instantiate_with => self.class }
  N4j::Traversal.new(:start => path)
end