Class: Neography::Relationship
- Inherits:
-
PropertyContainer
- Object
- OpenStruct
- PropertyContainer
- Neography::Relationship
- Defined in:
- lib/neography/relationship.rb
Instance Attribute Summary collapse
-
#end_node ⇒ Object
Returns the value of attribute end_node.
-
#rel_type ⇒ Object
Returns the value of attribute rel_type.
-
#start_node ⇒ Object
Returns the value of attribute start_node.
Attributes inherited from PropertyContainer
Class Method Summary collapse
- .create(type, from_node, to_node, props = nil) ⇒ Object
- .load(rel, db = Neography::Rest.new) ⇒ Object
Instance Method Summary collapse
- #del ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(hash = nil, server = nil) ⇒ Relationship
constructor
A new instance of Relationship.
- #neo_server ⇒ Object
- #neo_server=(server) ⇒ Object
- #other_node(node) ⇒ Object
Methods included from Index
#add_to_index, included, #remove_from_index
Methods included from Property
#[], #[]=, #attributes, #method_missing, #new_ostruct_member
Methods included from Equal
Constructor Details
#initialize(hash = nil, server = nil) ⇒ Relationship
Returns a new instance of Relationship.
32 33 34 35 36 37 38 |
# File 'lib/neography/relationship.rb', line 32 def initialize(hash=nil, server=nil) super(hash) @start_node = hash["start"].split('/').last @end_node = hash["end"].split('/').last @rel_type = hash["type"] self.neo_server = server end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Neography::Property
Instance Attribute Details
#end_node ⇒ Object
Returns the value of attribute end_node.
7 8 9 |
# File 'lib/neography/relationship.rb', line 7 def end_node @end_node end |
#rel_type ⇒ Object
Returns the value of attribute rel_type.
7 8 9 |
# File 'lib/neography/relationship.rb', line 7 def rel_type @rel_type end |
#start_node ⇒ Object
Returns the value of attribute start_node.
7 8 9 |
# File 'lib/neography/relationship.rb', line 7 def start_node @start_node end |
Class Method Details
.create(type, from_node, to_node, props = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/neography/relationship.rb', line 11 def create(type, from_node, to_node, props = nil) rel = Neography::Relationship.new(from_node.neo_server.create_relationship(type, from_node, to_node, props)) rel.start_node = from_node rel.end_node = to_node rel.rel_type = type rel end |
.load(rel, db = Neography::Rest.new) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/neography/relationship.rb', line 19 def load(rel, db = Neography::Rest.new) raise ArgumentError.new("syntax deprecated") if rel.is_a?(Neography::Rest) rel = db.get_relationship(rel) if rel rel = Neography::Relationship.new(rel, db) rel.start_node = Neography::Node.load(rel.start_node, db) rel.end_node = Neography::Node.load(rel.end_node, db) end rel end |
Instance Method Details
#del ⇒ Object
48 49 50 |
# File 'lib/neography/relationship.rb', line 48 def del start_node.neo_server.delete_relationship(neo_id) end |
#exist? ⇒ Boolean
52 53 54 55 56 57 58 59 |
# File 'lib/neography/relationship.rb', line 52 def exist? begin start_node.neo_server.get_relationship(neo_id) true rescue Neography::RelationshipNotFoundException false end end |
#neo_server ⇒ Object
40 41 42 |
# File 'lib/neography/relationship.rb', line 40 def neo_server @neo_server ||= self.start_node.neo_server end |
#neo_server=(server) ⇒ Object
44 45 46 |
# File 'lib/neography/relationship.rb', line 44 def neo_server=(server) @neo_server = server end |
#other_node(node) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/neography/relationship.rb', line 61 def other_node(node) if node == @start_node @end_node else @start_node end end |