Class: ROM::Changeset::Update
- Inherits:
-
ROM::Changeset
- Object
- ROM::Changeset
- ROM::Changeset::Update
- Defined in:
- lib/rom/repository/changeset/update.rb
Overview
Changeset specialization for update commands
Instance Attribute Summary collapse
-
#primary_key ⇒ Symbol
readonly
The name of the relation’s primary key attribute.
Attributes inherited from ROM::Changeset
Instance Method Summary collapse
-
#clean? ⇒ TrueClass, FalseClass
Return if there’s no diff between the original and changeset data.
-
#create? ⇒ FalseClass
Return false.
-
#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.
-
#update? ⇒ TrueClass
Return true.
Methods inherited from ROM::Changeset
default_pipe, #initialize, #map, #with
Constructor Details
This class inherits a constructor from ROM::Changeset
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ROM::Changeset
Instance Attribute Details
#primary_key ⇒ Symbol (readonly)
Returns The name of the relation’s primary key attribute.
9 |
# File 'lib/rom/repository/changeset/update.rb', line 9 option :primary_key, reader: true |
Instance Method Details
#clean? ⇒ TrueClass, FalseClass
Return if there’s no diff between the original and changeset data
62 63 64 |
# File 'lib/rom/repository/changeset/update.rb', line 62 def clean? diff.empty? end |
#create? ⇒ FalseClass
Return false
25 26 27 |
# File 'lib/rom/repository/changeset/update.rb', line 25 def create? false end |
#diff ⇒ Hash[
Calculate the diff between the original and changeset data
71 72 73 74 75 76 77 78 79 |
# File 'lib/rom/repository/changeset/update.rb', line 71 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
53 54 55 |
# File 'lib/rom/repository/changeset/update.rb', line 53 def diff? ! diff.empty? end |
#original ⇒ Hash
Return original tuple that this changeset may update
34 35 36 |
# File 'lib/rom/repository/changeset/update.rb', line 34 def original @original ||= relation.fetch(primary_key) end |
#to_h ⇒ Hash Also known as: to_hash
Return diff hash sent through the pipe
43 44 45 |
# File 'lib/rom/repository/changeset/update.rb', line 43 def to_h pipe.call(diff) end |
#update? ⇒ TrueClass
Return true
16 17 18 |
# File 'lib/rom/repository/changeset/update.rb', line 16 def update? true end |