Module Sequel::Plugins::Dirty::InstanceMethods
In: lib/sequel/plugins/dirty.rb

Methods

Attributes

previous_changes  [R]  A hash of previous changes before the object was saved, in the same format as column_changes. Note that this is not necessarily the same as the columns that were used in the update statement.

Public Instance methods

An array with the initial value and the current value of the column, if the column has been changed. If the column has not been changed, returns nil.

  column_change(:name) # => ['Initial', 'Current']

[Source]

    # File lib/sequel/plugins/dirty.rb, line 69
69:         def column_change(column)
70:           [initial_value(column), get_column_value(column)] if column_changed?(column)
71:         end

Either true or false depending on whether the column has changed. Note that this is not exactly the same as checking if the column is in changed_columns, if the column was not set initially.

  column_changed?(:name) # => true

[Source]

    # File lib/sequel/plugins/dirty.rb, line 91
91:         def column_changed?(column)
92:           initial_values.has_key?(column)
93:         end

A hash with column symbol keys and pairs of initial and current values for all changed columns.

  column_changes # => {:name => ['Initial', 'Current']}

[Source]

    # File lib/sequel/plugins/dirty.rb, line 77
77:         def column_changes
78:           h = {}
79:           initial_values.each do |column, value|
80:             h[column] = [value, get_column_value(column)]
81:           end
82:           h
83:         end

Freeze internal data structures

[Source]

     # File lib/sequel/plugins/dirty.rb, line 96
 96:         def freeze
 97:           initial_values.freeze
 98:           missing_initial_values.freeze
 99:           @previous_changes.freeze if @previous_changes
100:           super
101:         end

The initial value of the given column. If the column value has not changed, this will be the same as the current value of the column.

  initial_value(:name) # => 'Initial'

[Source]

     # File lib/sequel/plugins/dirty.rb, line 108
108:         def initial_value(column)
109:           initial_values.fetch(column){get_column_value(column)}
110:         end

A hash with column symbol keys and initial values.

  initial_values # {:name => 'Initial'}

[Source]

     # File lib/sequel/plugins/dirty.rb, line 115
115:         def initial_values
116:           @initial_values ||= {}
117:         end

Reset the column to its initial value. If the column was not set initial, removes it from the values.

  reset_column(:name)
  name # => 'Initial'

[Source]

     # File lib/sequel/plugins/dirty.rb, line 124
124:         def reset_column(column)
125:           if initial_values.has_key?(column)
126:             set_column_value("#{column}=""#{column}=", initial_values[column])
127:           end
128:           if missing_initial_values.include?(column)
129:             values.delete(column)
130:           end
131:         end

Manually specify that a column will change. This should only be used if you plan to modify a column value in place, which is not recommended.

  will_change_column(:name)
  name.gsub(/i/i, 'o')
  column_change(:name) # => ['Initial', 'onotoal']

[Source]

     # File lib/sequel/plugins/dirty.rb, line 139
139:         def will_change_column(column)
140:           _add_changed_column(column)
141:           check_missing_initial_value(column)
142: 
143:           value = if initial_values.has_key?(column)
144:             initial_values[column]
145:           else
146:             get_column_value(column)
147:           end
148: 
149:           initial_values[column] = if value && value != true && value.respond_to?(:clone)
150:             begin
151:               value.clone
152:             rescue TypeError
153:               value
154:             end
155:           else
156:             value
157:           end
158:         end

[Validate]