Class: ROM::Changeset::Update
- Inherits:
 - 
      Stateful
      
        
- Object
 - ROM::Changeset
 - Stateful
 - ROM::Changeset::Update
 
 
- Defined in:
 - changeset/lib/rom/changeset/update.rb
 
Overview
Changeset specialization for update commands
Update changesets will only execute their commands when
the data is different from the original tuple. Original tuple
is fetched from changeset's relation using one method.
Instance Method Summary collapse
- 
  
    
      #clean?  ⇒ TrueClass, FalseClass 
    
    
  
  
  
  
  
  
  
  
  
    
Return if there's no diff between the original and changeset data.
 - 
  
    
      #commit  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Commit update changeset if there's a diff.
 - 
  
    
      #diff  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Calculate the diff between the original and changeset data.
 - 
  
    
      #diff?  ⇒ TrueClass, FalseClass 
    
    
  
  
  
  
  
  
  
  
  
    
Return true if there's a diff between original and changeset data.
 - 
  
    
      #original  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Return original tuple that this changeset may update.
 
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ROM::Changeset::Stateful
Instance Method Details
#clean? ⇒ TrueClass, FalseClass
Return if there's no diff between the original and changeset data
      56 57 58  | 
    
      # File 'changeset/lib/rom/changeset/update.rb', line 56 def clean? diff.empty? end  | 
  
#commit ⇒ Hash
Commit update changeset if there's a diff
This returns original tuple if there's no diff
      29 30 31  | 
    
      # File 'changeset/lib/rom/changeset/update.rb', line 29 def commit diff? ? super : original end  | 
  
#diff ⇒ Hash
Calculate the diff between the original and changeset data
      65 66 67 68 69 70 71 72 73 74 75 76 77 78  | 
    
      # File 'changeset/lib/rom/changeset/update.rb', line 65 def diff @diff ||= begin source = Hash(original) data = pipe.for_diff(__data__) data_tuple = data.to_a data_keys = data.keys & source.keys new_tuple = data_tuple.to_a.select { |k, _| data_keys.include?(k) } ori_tuple = source.to_a.select { |k, _| data_keys.include?(k) } Hash[new_tuple - (new_tuple & ori_tuple)] end end  | 
  
#diff? ⇒ TrueClass, FalseClass
Return true if there's a diff between original and changeset data
      47 48 49  | 
    
      # File 'changeset/lib/rom/changeset/update.rb', line 47 def diff? !diff.empty? end  | 
  
#original ⇒ Hash
Return original tuple that this changeset may update
      38 39 40  | 
    
      # File 'changeset/lib/rom/changeset/update.rb', line 38 def original @original ||= relation.one end  |