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
72 73 74 |
# File 'lib/active_node/persistence.rb', line 72 def [](attr) declared?(attr) ? send(attr) : @hash[attr] end |
#[]=(attr, value) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/active_node/persistence.rb', line 76 def []=(attr, value) if declared? attr write_attr attr, value else @hash[attr]=value end end |
#destroy(include_relationships = false) ⇒ Object
112 113 114 115 116 |
# File 'lib/active_node/persistence.rb', line 112 def destroy include_relationships=false destroyable = destroy_associations include_relationships Neo.db.delete_node(id) if destroyable @destroyed = destroyable end |
#destroy! ⇒ Object
122 123 124 |
# File 'lib/active_node/persistence.rb', line 122 def destroy! destroy true end |
#destroyed? ⇒ Boolean
118 119 120 |
# File 'lib/active_node/persistence.rb', line 118 def destroyed? @destroyed end |
#includes!(includes) ⇒ Object
134 135 136 |
# File 'lib/active_node/persistence.rb', line 134 def includes!(includes) new_record? ? self : self.class.includes(includes).build(self).first end |
#incoming(type = nil, klass = nil) ⇒ Object
126 127 128 |
# File 'lib/active_node/persistence.rb', line 126 def incoming(type=nil, klass=nil) (:incoming, type, klass) end |
#initialize(hash = {}, split_by = :respond_to_writer?) ⇒ Object
96 97 98 99 |
# File 'lib/active_node/persistence.rb', line 96 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
84 85 86 |
# File 'lib/active_node/persistence.rb', line 84 def neo_id id end |
#new_record? ⇒ Boolean
101 102 103 |
# File 'lib/active_node/persistence.rb', line 101 def new_record? !id end |
#outgoing(type = nil, klass = nil) ⇒ Object
130 131 132 |
# File 'lib/active_node/persistence.rb', line 130 def outgoing(type=nil, klass=nil) (:outgoing, type, klass) end |
#persisted? ⇒ Boolean
92 93 94 |
# File 'lib/active_node/persistence.rb', line 92 def persisted? id.present? && !destroyed? end |
#save ⇒ Object Also known as: save!
105 106 107 108 |
# File 'lib/active_node/persistence.rb', line 105 def save(*) create_or_update super end |
#to_param ⇒ Object
88 89 90 |
# File 'lib/active_node/persistence.rb', line 88 def to_param id.to_s if persisted? end |
#update_attribute(key, value) ⇒ Object
143 144 145 146 |
# File 'lib/active_node/persistence.rb', line 143 def update_attribute(key, value) modify_attribute(key, value) save!(validate: false) end |
#update_attributes(attributes) ⇒ Object
138 139 140 141 |
# File 'lib/active_node/persistence.rb', line 138 def update_attributes attributes attributes.each { |key, value| modify_attribute(key, value) } save end |