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



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

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

#destroy!Object



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

def destroy!
  destroy true
end

#destroyed?Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#includes!(includes) ⇒ Object



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

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

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



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

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

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



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

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



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

def neo_id
  id
end

#new_record?Boolean

Returns:

  • (Boolean)


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

def new_record?
  !id
end

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



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

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

#persisted?Boolean

Returns:

  • (Boolean)


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

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

#saveObject Also known as: save!



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

def save(*)
  create_or_update
  super
end

#to_paramObject



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

def to_param
  id.to_s if persisted?
end

#update_attribute(key, value) ⇒ Object



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

def update_attribute(key, value)
  modify_attribute(key, value)
  save!(validate: false)
end

#update_attributes(attributes) ⇒ Object



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

def update_attributes attributes
  attributes.each { |key, value| modify_attribute(key, value) }
  save
end