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
- #[](attr) ⇒ Object
- #[]=(attr, value) ⇒ Object
- #destroy(include_relationships = false) ⇒ Object
- #destroy! ⇒ Object
- #destroyed? ⇒ Boolean
- #includes!(includes) ⇒ Object
- #incoming(type = nil, klass = nil) ⇒ Object
- #initialize(hash = {}, split_by = :respond_to_writer?) ⇒ Object
- #neo_id ⇒ Object
- #new_record? ⇒ Boolean
- #outgoing(type = nil, klass = nil) ⇒ Object
- #persisted? ⇒ Boolean
- #save ⇒ Object (also: #save!)
- #to_param ⇒ Object
- #update_attribute(key, value) ⇒ Object
- #update_attributes(attributes) ⇒ Object
Instance Method Details
#[](attr) ⇒ Object
87 88 89 |
# File 'lib/active_node/persistence.rb', line 87 def [](attr) declared?(attr) ? send(attr) : @hash[attr] end |
#[]=(attr, value) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/active_node/persistence.rb', line 91 def []=(attr, value) if declared? attr write_attr attr, value else @hash[attr]=value end end |
#destroy(include_relationships = false) ⇒ Object
127 128 129 130 131 |
# File 'lib/active_node/persistence.rb', line 127 def destroy include_relationships=false destroyable = destroy_associations include_relationships Neo.db.delete_node(id) if destroyable @destroyed = destroyable end |
#destroy! ⇒ Object
137 138 139 |
# File 'lib/active_node/persistence.rb', line 137 def destroy! destroy true end |
#destroyed? ⇒ Boolean
133 134 135 |
# File 'lib/active_node/persistence.rb', line 133 def destroyed? @destroyed end |
#includes!(includes) ⇒ Object
149 150 151 |
# File 'lib/active_node/persistence.rb', line 149 def includes!(includes) new_record? ? self : self.class.includes(includes).build(self).first end |
#incoming(type = nil, klass = nil) ⇒ Object
141 142 143 |
# File 'lib/active_node/persistence.rb', line 141 def incoming(type=nil, klass=nil) (:incoming, type, klass) end |
#initialize(hash = {}, split_by = :respond_to_writer?) ⇒ Object
111 112 113 114 |
# File 'lib/active_node/persistence.rb', line 111 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
99 100 101 |
# File 'lib/active_node/persistence.rb', line 99 def neo_id id end |
#new_record? ⇒ Boolean
116 117 118 |
# File 'lib/active_node/persistence.rb', line 116 def new_record? !id end |
#outgoing(type = nil, klass = nil) ⇒ Object
145 146 147 |
# File 'lib/active_node/persistence.rb', line 145 def outgoing(type=nil, klass=nil) (:outgoing, type, klass) end |
#persisted? ⇒ Boolean
107 108 109 |
# File 'lib/active_node/persistence.rb', line 107 def persisted? id.present? && !destroyed? end |
#save ⇒ Object Also known as: save!
120 121 122 123 |
# File 'lib/active_node/persistence.rb', line 120 def save(*) create_or_update super end |
#to_param ⇒ Object
103 104 105 |
# File 'lib/active_node/persistence.rb', line 103 def to_param id.to_s if persisted? end |
#update_attribute(key, value) ⇒ Object
158 159 160 161 |
# File 'lib/active_node/persistence.rb', line 158 def update_attribute(key, value) modify_attribute(key, value) save!(validate: false) end |
#update_attributes(attributes) ⇒ Object
153 154 155 156 |
# File 'lib/active_node/persistence.rb', line 153 def update_attributes attributes attributes.each { |key, value| modify_attribute(key, value) } save end |