Module: ActiveNode::Persistence

Extended by:
ActiveSupport::Concern
Includes:
Neography::Rest::Helpers
Included in:
Base
Defined in:
lib/active_node/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#[](attr) ⇒ Object



67
68
69
# File 'lib/active_node/persistence.rb', line 67

def [](attr)
  declared?(attr) ? send(attr) : @hash[attr]
end

#[]=(attr, value) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/active_node/persistence.rb', line 71

def []=(attr, value)
  if declared? attr
    send "#{attr}=", value
  else
    @hash[attr]=value
  end
end

#destroy(include_relationships = false) ⇒ Object



106
107
108
109
110
# File 'lib/active_node/persistence.rb', line 106

def destroy include_relationships=false
  destroyable = destroy_associations include_relationships
  Neo.db.delete_node(id) if destroyable
  @destroyed = destroyable
end

#destroy!Object



112
113
114
# File 'lib/active_node/persistence.rb', line 112

def destroy!
  destroy true
end

#incoming(type = nil, klass = nil) ⇒ Object



116
117
118
# File 'lib/active_node/persistence.rb', line 116

def incoming(type=nil, klass=nil)
  related(:incoming, type, klass)
end

#initialize(hash = {}, split_by = :respond_to_writer?) ⇒ Object



91
92
93
94
# File 'lib/active_node/persistence.rb', line 91

def initialize hash={}, split_by=:respond_to_writer?
  super(split_hash hash, :select, split_by)
  @hash=(split_hash(hash, :reject, split_by) || {}).with_indifferent_access
end

#neo_idObject



79
80
81
# File 'lib/active_node/persistence.rb', line 79

def neo_id
  id
end

#new_record?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/active_node/persistence.rb', line 96

def new_record?
  !id
end

#outgoing(type = nil, klass = nil) ⇒ Object



120
121
122
# File 'lib/active_node/persistence.rb', line 120

def outgoing(type=nil, klass=nil)
  related(:outgoing, type, klass)
end

#persisted?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/active_node/persistence.rb', line 87

def persisted?
  id
end

#relationships(reflection, *associations) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/active_node/persistence.rb', line 124

def relationships(reflection, *associations)
  id ?
      Neo.db.execute_query(
          "start n=node({id}) match #{match reflection}#{optional_match reflection, associations} return #{list_with_rel reflection.name, *associations} order by #{created_at_list reflection.name, *associations}",
          {id: id})['data'].map { |rel_node| self.class.wrap_rel rel_node[0], rel_node[1], reflection.klass } :
      []
end

#saveObject Also known as: save!



100
101
102
# File 'lib/active_node/persistence.rb', line 100

def save(*)
  create_or_update
end

#to_paramObject



83
84
85
# File 'lib/active_node/persistence.rb', line 83

def to_param
  id
end