Class: ROM::Changeset::Update
- Inherits:
-
Stateful
- Object
- ROM::Changeset
- Stateful
- ROM::Changeset::Update
- Includes:
- Restricted
- Defined in:
- lib/rom/repository/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 ‘by_pk` relation view. This means the underlying adapter must provide this view, or you you need to implement it yourself in your relations if you want to use Update changesets.
Instance Method Summary collapse
-
#clean? ⇒ TrueClass, FalseClass
Return if there’s no diff between the original and changeset data.
-
#command ⇒ Object
included
from Restricted
private
Return a command restricted by the changeset’s relation.
-
#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.
-
#to_h ⇒ Hash
(also: #to_hash)
Return diff hash sent through the pipe.
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
68 69 70 |
# File 'lib/rom/repository/changeset/update.rb', line 68 def clean? diff.empty? end |
#command ⇒ Object Originally defined in module Restricted
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a command restricted by the changeset’s relation
#commit ⇒ Hash
Commit update changeset if there’s a diff
This returns original tuple if there’s no diff
31 32 33 |
# File 'lib/rom/repository/changeset/update.rb', line 31 def commit diff? ? super : original end |
#diff ⇒ Hash
Calculate the diff between the original and changeset data
77 78 79 80 81 82 83 84 85 |
# File 'lib/rom/repository/changeset/update.rb', line 77 def diff @diff ||= begin new_tuple = __data__.to_a ori_tuple = original.to_a Hash[new_tuple - (new_tuple & ori_tuple)] end end |
#diff? ⇒ TrueClass, FalseClass
Return true if there’s a diff between original and changeset data
59 60 61 |
# File 'lib/rom/repository/changeset/update.rb', line 59 def diff? ! diff.empty? end |
#original ⇒ Hash
Return original tuple that this changeset may update
40 41 42 |
# File 'lib/rom/repository/changeset/update.rb', line 40 def original @original ||= Hash(relation.one) end |
#to_h ⇒ Hash Also known as: to_hash
Return diff hash sent through the pipe
49 50 51 |
# File 'lib/rom/repository/changeset/update.rb', line 49 def to_h pipe.call(diff) end |