Module: ActiveNode::Persistence::ClassMethods
- Defined in:
- lib/active_node/persistence.rb
Instance Method Summary collapse
- #active_node_class(class_name, default_klass = nil) ⇒ Object
- #all ⇒ Object
- #create_rel(rel, node) ⇒ Object
- #find(ids, options = {}) ⇒ Object
- #find_by_cypher(query, params = {}, klass = nil) ⇒ Object
- #label ⇒ Object
- #timestamps ⇒ Object
- #wrap(node, klass = nil) ⇒ Object
- #wrap_rel(rel, node, klass) ⇒ Object
Instance Method Details
#active_node_class(class_name, default_klass = nil) ⇒ Object
48 49 50 51 |
# File 'lib/active_node/persistence.rb', line 48 def active_node_class(class_name, default_klass=nil) klass = Module.const_get(class_name) rescue nil klass && klass < ActiveNode::Base && klass || default_klass end |
#all ⇒ Object
28 29 30 |
# File 'lib/active_node/persistence.rb', line 28 def all new_instances(Neo.db.get_nodes_labeled(label), self) end |
#create_rel(rel, node) ⇒ Object
44 45 46 |
# File 'lib/active_node/persistence.rb', line 44 def create_rel rel, node ActiveNode::Relationship.new node, rel['data'].merge(id: get_id(rel).to_i) end |
#find(ids, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/active_node/persistence.rb', line 19 def find ids, ={} array = ActiveNode::Graph::Builder.new(self, *[:include]).build(*ids) ids.is_a?(Array) ? array : array.first end |
#find_by_cypher(query, params = {}, klass = nil) ⇒ Object
24 25 26 |
# File 'lib/active_node/persistence.rb', line 24 def find_by_cypher query, params={}, klass=nil wrap(Neo.db.execute_query(query, params)['data'].map(&:first), klass) end |
#label ⇒ Object
32 33 34 |
# File 'lib/active_node/persistence.rb', line 32 def label name end |
#timestamps ⇒ Object
14 15 16 17 |
# File 'lib/active_node/persistence.rb', line 14 def attribute :created_at, type: String attribute :updated_at, type: String end |
#wrap(node, klass = nil) ⇒ Object
36 37 38 |
# File 'lib/active_node/persistence.rb', line 36 def wrap node, klass=nil node.is_a?(Array) ? new_instances(node, klass) : new_instance(node, klass) end |
#wrap_rel(rel, node, klass) ⇒ Object
40 41 42 |
# File 'lib/active_node/persistence.rb', line 40 def wrap_rel rel, node, klass create_rel rel, wrap(node, klass) end |