Class: Holistic::Database::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/holistic/database/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, attributes) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
# File 'lib/holistic/database/node.rb', line 6

def initialize(id, attributes)
  @id = id
  @attributes = attributes
  @relations = ::Hash.new(&method(:build_relation_hash))
end

Instance Attribute Details

#__database__Object

Returns the value of attribute __database__.



4
5
6
# File 'lib/holistic/database/node.rb', line 4

def __database__
  @__database__
end

#attributesObject

Returns the value of attribute attributes.



4
5
6
# File 'lib/holistic/database/node.rb', line 4

def attributes
  @attributes
end

#relationsObject

Returns the value of attribute relations.



4
5
6
# File 'lib/holistic/database/node.rb', line 4

def relations
  @relations
end

Instance Method Details

#attr(attribute_name) ⇒ Object



12
13
14
# File 'lib/holistic/database/node.rb', line 12

def attr(attribute_name)
  @attributes[attribute_name]
end

#has_many(connection_name) ⇒ Object



20
21
22
# File 'lib/holistic/database/node.rb', line 20

def has_many(connection_name)
  @relations[connection_name].to_a
end

#has_one(connection_name) ⇒ Object



24
25
26
# File 'lib/holistic/database/node.rb', line 24

def has_one(connection_name)
  @relations[connection_name].first
end

#relation(relation_name) ⇒ Object



16
17
18
# File 'lib/holistic/database/node.rb', line 16

def relation(relation_name)
  @relations[relation_name]
end