Module: ActiveGraph::Node::Persistence
- Extended by:
 - ActiveSupport::Concern, Forwardable
 
- Includes:
 - Shared::Persistence
 
- Included in:
 - ActiveGraph::Node
 
- Defined in:
 - lib/active_graph/node/persistence.rb
 
Defined Under Namespace
Modules: ClassMethods Classes: RecordInvalidError
Instance Method Summary collapse
- 
  
    
      #_create_node(node_props, labels = labels_for_create)  ⇒ ActiveGraph::Node 
    
    
  
  
  
  
  
  
  
  
  
    
TODO: This does not seem like it should be the responsibility of the node.
 - 
  
    
      #concurrent_increment!(attribute, by = 1)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Increments concurrently a numeric attribute by a centain amount.
 - 
  
    
      #create_model  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Creates a model with values matching those of the instance attributes and returns its id.
 - 
  
    
      #labels_for_create  ⇒ Array 
    
    
  
  
  
  
  
  
  
  
  
    
Labels to be set on the node during a create event.
 - 
  
    
      #save  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Saves the model.
 - 
  
    
      #save!(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Persist the object to the database.
 
Methods included from Shared::Persistence
#apply_default_values, #cache_key, #create_or_update, #destroy, #destroyed?, #exist?, #freeze, #frozen?, #increment, #increment!, #inject_primary_key!, #new_record?, #persisted?, #props, #props_for_create, #props_for_persistence, #props_for_update, #reload, #reload_from_database, #skip_update?, #touch, #update, #update!, #update_attribute, #update_attribute!, #update_db_properties, #update_db_property, #update_model
Instance Method Details
#_create_node(node_props, labels = labels_for_create) ⇒ ActiveGraph::Node
TODO: This does not seem like it should be the responsibility of the node. Creates an unwrapped node in the database.
      68 69 70 71  | 
    
      # File 'lib/active_graph/node/persistence.rb', line 68 def _create_node(node_props, labels = labels_for_create) query = "CREATE (n:`#{Array(labels).join('`:`')}`) SET n = $props RETURN n" neo4j_query(query, {props: node_props}, wrap: false).to_a[0][:n] end  | 
  
#concurrent_increment!(attribute, by = 1) ⇒ Object
Increments concurrently a numeric attribute by a centain amount
      35 36 37  | 
    
      # File 'lib/active_graph/node/persistence.rb', line 35 def concurrent_increment!(attribute, by = 1) increment_by_query! query_as(:n), attribute, by end  | 
  
#create_model ⇒ Object
Creates a model with values matching those of the instance attributes and returns its id.
      56 57 58 59 60 61  | 
    
      # File 'lib/active_graph/node/persistence.rb', line 56 def create_model node = _create_node(props_for_create) init_on_load(node, node.properties) @deferred_nodes = nil true end  | 
  
#labels_for_create ⇒ Array
Returns Labels to be set on the node during a create event.
      74 75 76  | 
    
      # File 'lib/active_graph/node/persistence.rb', line 74 def labels_for_create self.class.mapped_label_names end  | 
  
#save ⇒ Object
Saves the model.
If the model is new a record gets created in the database, otherwise the existing record gets updated. If perform_validation is true validations run. If any of them fail the action is cancelled and save returns false. If the flag is false validations are bypassed altogether. See ActiveRecord::Validations for more information. There’s a series of callbacks associated with save. If any of the before_* callbacks return false the action is cancelled and save returns false.
      25 26 27 28 29 30  | 
    
      # File 'lib/active_graph/node/persistence.rb', line 25 def save(*) cascade_save do association_proxy_cache.clear create_or_update end end  | 
  
#save!(*args) ⇒ Object
Persist the object to the database. Validations and Callbacks are included by default but validation can be disabled by passing :validate => false to #save! Creates a new transaction.
      49 50 51  | 
    
      # File 'lib/active_graph/node/persistence.rb', line 49 def save!(*args) save(*args) or fail(RecordInvalidError, self) # rubocop:disable Style/AndOr end  |