Module: DeltaChanges::Extension

Defined in:
lib/delta_changes.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods, InstanceMethodsLegacy

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/delta_changes.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
  base.cattr_accessor :delta_changes_options
  base.attribute_method_suffix '_delta_changed?', '_delta_change', '_delta_was', '_delta_will_change!'
  if ::ActiveRecord.version < Gem::Version.new('5.2')
    base.send(:prepend, InstanceMethodsLegacy)
  else
    base.send(:prepend, InstanceMethods)
  end
end

Instance Method Details

#delta_changesObject



92
93
94
# File 'lib/delta_changes.rb', line 92

def delta_changes
  delta_changed_attributes.keys.inject({}) { |h, attr| h[attr] = attribute_delta_change(attr); h }
end

#delta_changes?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/delta_changes.rb', line 96

def delta_changes?
  delta_changed_attributes.keys.present?
end

#reset_delta_changes!Object



102
103
104
# File 'lib/delta_changes.rb', line 102

def reset_delta_changes!
  delta_changed_attributes.clear
end