Class: ROM::Changeset::Update

Inherits:
ROM::Changeset show all
Defined in:
lib/rom/repository/changeset/update.rb

Overview

Changeset specialization for update commands

Instance Attribute Summary collapse

Attributes inherited from ROM::Changeset

#data, #pipe, #relation

Instance Method Summary collapse

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_keySymbol (readonly)

Returns The name of the relation’s primary key attribute.

Returns:

  • (Symbol)

    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

Returns:

  • (TrueClass, FalseClass)


62
63
64
# File 'lib/rom/repository/changeset/update.rb', line 62

def clean?
  diff.empty?
end

#create?FalseClass

Return false

Returns:

  • (FalseClass)


25
26
27
# File 'lib/rom/repository/changeset/update.rb', line 25

def create?
  false
end

#diffHash[

Calculate the diff between the original and changeset data

Returns:

  • (Hash[)

    Hash[



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

Returns:

  • (TrueClass, FalseClass)


53
54
55
# File 'lib/rom/repository/changeset/update.rb', line 53

def diff?
  ! diff.empty?
end

#originalHash

Return original tuple that this changeset may update

Returns:

  • (Hash)


34
35
36
# File 'lib/rom/repository/changeset/update.rb', line 34

def original
  @original ||= relation.fetch(primary_key)
end

#to_hHash Also known as: to_hash

Return diff hash sent through the pipe

Returns:

  • (Hash)


43
44
45
# File 'lib/rom/repository/changeset/update.rb', line 43

def to_h
  pipe.call(diff)
end

#update?TrueClass

Return true

Returns:

  • (TrueClass)


16
17
18
# File 'lib/rom/repository/changeset/update.rb', line 16

def update?
  true
end