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



69
70
71
# File 'lib/active_node/persistence.rb', line 69

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

#[]=(attr, value) ⇒ Object



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

def []=(attr, value)
  if declared? attr
    write_attr attr, value
  else
    @hash[attr]=value
  end
end

#destroy(include_relationships = false) ⇒ Object



113
114
115
116
117
# File 'lib/active_node/persistence.rb', line 113

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

#destroy! ⇒ Object



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

def destroy!
  destroy true
end

#destroyed? ⇒ Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#includes!(includes) ⇒ Object



135
136
137
# File 'lib/active_node/persistence.rb', line 135

def includes!(includes)
  new_record? ? self : self.class.includes(includes).build(self).first
end

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



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

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

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



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

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_id ⇒ Object



81
82
83
# File 'lib/active_node/persistence.rb', line 81

def neo_id
  id
end

#new_record? ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/active_node/persistence.rb', line 102

def new_record?
  !id
end

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



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

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

#persisted? ⇒ Boolean

Returns:

  • (Boolean)


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

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

#save ⇒ Object Also known as: save!



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

def save(*)
  create_or_update
  super
end

#to_key ⇒ Object



89
90
91
# File 'lib/active_node/persistence.rb', line 89

def to_key
  id
end

#to_param ⇒ Object



85
86
87
# File 'lib/active_node/persistence.rb', line 85

def to_param
  id.to_s if persisted?
end

#update_attributes(attributes) ⇒ Object



139
140
141
142
# File 'lib/active_node/persistence.rb', line 139

def update_attributes attributes
  attributes.each { |key, value| respond_to_writer?(attr) ? write_attr(key, value) : self[key]=value }
  save
end