Class: ActiveNode::Graph
- Inherits:
-
Object
- Object
- ActiveNode::Graph
- Includes:
- FinderMethods, QueryMethods, Neography::Rest::Helpers
- Defined in:
- lib/active_node/graph.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#loaded ⇒ Object
(also: #loaded?)
readonly
Returns the value of attribute loaded.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#reflections ⇒ Object
readonly
Returns the value of attribute reflections.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compares two relations for equality.
- #all ⇒ Object
- #build(*objects) ⇒ Object
- #count ⇒ Object
-
#delete_all ⇒ Object
def first limit 1 to_a.first end.
- #includes(*includes) ⇒ Object
-
#initialize(klass, *includes) ⇒ Graph
constructor
A new instance of Graph.
- #limit(count) ⇒ Object
- #load ⇒ Object
- #pretty_print(q) ⇒ Object
- #to_a ⇒ Object
- #where(hash) ⇒ Object
Methods included from FinderMethods
#find, #find_by, #find_by!, #first, #first!, #last, #last!, #raise_record_not_found_exception!, #take, #take!
Methods included from QueryMethods
#limit_value, #offset, #offset_value, #order, #order_values, #reverse_order
Constructor Details
#initialize(klass, *includes) ⇒ Graph
Returns a new instance of Graph.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_node/graph.rb', line 11 def initialize klass, *includes @klass = klass if klass < ActiveNode::Base @matches = [] @reflections =[] @object_cache = {} @relationship_cache = {} @loaded_assoc_cache = {} @where = {} @includes = includes @offsets = {} end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/active_node/graph.rb', line 6 def klass @klass end |
#loaded ⇒ Object (readonly) Also known as: loaded?
Returns the value of attribute loaded.
6 7 8 |
# File 'lib/active_node/graph.rb', line 6 def loaded @loaded end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
6 7 8 |
# File 'lib/active_node/graph.rb', line 6 def matches @matches end |
#reflections ⇒ Object (readonly)
Returns the value of attribute reflections.
6 7 8 |
# File 'lib/active_node/graph.rb', line 6 def reflections @reflections end |
Instance Method Details
#==(other) ⇒ Object
Compares two relations for equality.
61 62 63 64 65 66 67 68 |
# File 'lib/active_node/graph.rb', line 61 def ==(other) case other when Graph other.to_cypher == to_cypher when Array to_a == other end end |
#all ⇒ Object
23 24 25 |
# File 'lib/active_node/graph.rb', line 23 def all self end |
#build(*objects) ⇒ Object
46 47 48 |
# File 'lib/active_node/graph.rb', line 46 def build *objects find objects.map { |o| o.is_a?(ActiveNode::Base) ? o.id.tap { |id| @object_cache[id]=o } : extract_id(o) } end |
#count ⇒ Object
27 28 29 |
# File 'lib/active_node/graph.rb', line 27 def count to_a.count end |
#delete_all ⇒ Object
def first limit 1 to_a.first end
79 80 81 |
# File 'lib/active_node/graph.rb', line 79 def delete_all Neo.db.execute_query("#{initial_match} OPTIONAL MATCH (n0)-[r]-() DELETE n0,r") end |
#includes(*includes) ⇒ Object
31 32 33 34 |
# File 'lib/active_node/graph.rb', line 31 def includes *includes @includes += includes self end |
#limit(count) ⇒ Object
41 42 43 44 |
# File 'lib/active_node/graph.rb', line 41 def limit count @limit = count self end |
#load ⇒ Object
50 51 52 53 |
# File 'lib/active_node/graph.rb', line 50 def load parse_results execute unless loaded? self end |
#pretty_print(q) ⇒ Object
70 71 72 |
# File 'lib/active_node/graph.rb', line 70 def pretty_print(q) q.pp(self.to_a) end |
#to_a ⇒ Object
55 56 57 58 |
# File 'lib/active_node/graph.rb', line 55 def to_a load @records end |
#where(hash) ⇒ Object
36 37 38 39 |
# File 'lib/active_node/graph.rb', line 36 def where hash @where.merge! hash if hash self end |