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



71
72
73
# File 'lib/active_node/persistence.rb', line 71

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

#[]=(attr, value) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/active_node/persistence.rb', line 75

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

#destroy(include_relationships = false) ⇒ Object



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

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

#destroy!Object



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

def destroy!
  destroy true
end

#destroyed?Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

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



124
125
126
# File 'lib/active_node/persistence.rb', line 124

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

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



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

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



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

def neo_id
  id
end

#new_record?Boolean

Returns:

  • (Boolean)


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

def new_record?
  !id
end

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



128
129
130
# File 'lib/active_node/persistence.rb', line 128

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

#persisted?Boolean

Returns:

  • (Boolean)


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

def persisted?
  id.present? && !destroyed?
end

#relationships(reflection, *associations) ⇒ Object



132
133
134
# File 'lib/active_node/persistence.rb', line 132

def relationships(reflection, *associations)
  ActiveNode::Graph::Builder.new(self.class, reflection.name => associations).build(self)
end

#saveObject Also known as: save!



104
105
106
# File 'lib/active_node/persistence.rb', line 104

def save(*)
  create_or_update
end

#to_paramObject



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

def to_param
  id.to_s if persisted?
end