Module: Neoid::ModelAdditions::InstanceMethods
- Defined in:
- lib/neoid/model_additions.rb
Instance Method Summary collapse
- #neo_destroy ⇒ Object
- #neo_save ⇒ Object (also: #neo_create, #neo_update)
- #neo_save_after_model_save ⇒ Object
- #neo_unique_id ⇒ Object
- #to_neo ⇒ Object
Instance Method Details
#neo_destroy ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/neoid/model_additions.rb', line 62 def neo_destroy return if @_neo_destroyed @_neo_destroyed = true neo_representation = neo_find_by_id return unless neo_representation begin neo_representation.del rescue Neography::NodeNotFoundException => e Neoid::logger.info "Neoid#neo_destroy entity not found #{self.class.name} #{self.id}" end # Not working yet because Neography can't delete a node and all of its realtionships in a batch, and deleting a node with relationships results an error # if Neoid::Batch.current_batch # Neoid::Batch.current_batch << [self.class.delete_command, neo_representation.neo_id] # else # begin # neo_representation.del # rescue Neography::NodeNotFoundException => e # Neoid::logger.info "Neoid#neo_destroy entity not found #{self.class.name} #{self.id}" # end # end _reset_neo_representation true end |
#neo_save ⇒ Object Also known as: neo_create, neo_update
54 55 56 57 |
# File 'lib/neoid/model_additions.rb', line 54 def neo_save @_neo_destroyed = false @_neo_representation = _neo_save end |
#neo_save_after_model_save ⇒ Object
48 49 50 51 52 |
# File 'lib/neoid/model_additions.rb', line 48 def neo_save_after_model_save return unless self.class.neoid_config.auto_index neo_save true end |
#neo_unique_id ⇒ Object
91 92 93 |
# File 'lib/neoid/model_additions.rb', line 91 def neo_unique_id "#{self.class.name}:#{self.id}" end |
#to_neo ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/neoid/model_additions.rb', line 30 def to_neo if self.class.neoid_config.stored_fields hash = self.class.neoid_config.stored_fields.inject({}) do |all, (field, block)| all[field] = if block instance_eval(&block) else self.send(field) rescue (raise "No field #{field} for #{self.class.name}") end all end hash.reject { |k, v| v.nil? } else {} end end |