module Gourami::Extensions::Changes

Constants

WATCH_CHANGES_VALID_RETURN_VALUES

Public Class Methods

included(klass) click to toggle source
# File lib/gourami/extensions/changes.rb, line 41
def self.included(klass)
  klass.send(:extend, ClassMethods)
end

Public Instance Methods

changes?(attribute_name) click to toggle source
# File lib/gourami/extensions/changes.rb, line 45
def changes?(attribute_name)
  attribute_name_sym = attribute_name.to_sym
  changed_attributes.fetch(attribute_name_sym) do
    options = self.class.attributes.fetch(attribute_name_sym, {})
    watch_changes = options.fetch(:watch_changes, false)

    return false if watch_changes

    raise NotWatchingChangesError, "`#{attribute_name}` is not being watched for changes. " \
      "Try `attribute(:#{attribute_name}, :watch_changes => true)`"
  end
end
did_change(attribute_name, changed = true) click to toggle source
# File lib/gourami/extensions/changes.rb, line 58
def did_change(attribute_name, changed = true)
  changed_attributes[attribute_name.to_sym] = !!changed
end

Private Instance Methods

changed_attributes() click to toggle source
# File lib/gourami/extensions/changes.rb, line 64
def changed_attributes
  @changed_attributes ||= {}
end