module ActiveResource::Dirty

Constants

VERSION

Public Instance Methods

changes_applied() click to toggle source

Monkey patch

Calls superclass method
# File lib/active_resource/dirty.rb, line 40
def changes_applied
  if new_active_model_version?
    super
  else
    @previously_changed = changes
    @attributes_changed_by_setter = ActiveSupport::HashWithIndifferentAccess.new
  end
end
reload(*) click to toggle source

reload the record and clears changed attributes.

Calls superclass method
# File lib/active_resource/dirty.rb, line 15
def reload(*)
  super.tap do
    clear_changes_information
  end
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/active_resource/dirty.rb, line 35
def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('=') || super
end
save_without_validation(*) click to toggle source

Save the record and clears changed attributes if successful.

# File lib/active_resource/dirty.rb, line 6
def save_without_validation(*)
  run_callbacks :save do
    saved = new? ? create : update
    changes_applied if saved
    saved
  end
end
update_attributes(attributes) click to toggle source
# File lib/active_resource/dirty.rb, line 21
def update_attributes(attributes)
  unless attributes.respond_to?(:to_hash)
    raise ArgumentError, 'expected attributes to be able to convert'\
      " to Hash, got #{attributes.inspect}"
  end

  attributes = attributes.to_hash
  attributes.each do |key, value|
    send("#{key}=".to_sym, value)
  end

  save
end

Protected Instance Methods

update() click to toggle source

Update the resource on the remote service.

Calls superclass method
# File lib/active_resource/dirty.rb, line 90
def update
  return super unless patch_updates

  return if changed_attributes.blank?

  run_callbacks :update do
    connection.patch(element_path(prefix_options),
                     encode(only: keys_for_partial_write),
                     self.class.headers).tap do |response|
      load_attributes_from_response(response)
    end
  end
end

Private Instance Methods

forget_attribute_assignments() click to toggle source

Monkey patch

# File lib/active_resource/dirty.rb, line 81
def forget_attribute_assignments; end
keys_for_partial_write() click to toggle source
# File lib/active_resource/dirty.rb, line 83
def keys_for_partial_write
  changed_attributes.keys
end
mutations_from_database() click to toggle source

Monkey patch

# File lib/active_resource/dirty.rb, line 72
def mutations_from_database
  @mutations_from_database ||= if new_active_model_version?
                                 ActiveModel::ForcedMutationTracker.new(self)
                               else
                                 ActiveModel::NullMutationTracker.instance
                               end
end
new_active_model_version?() click to toggle source
# File lib/active_resource/dirty.rb, line 51
def new_active_model_version?
  ActiveModel::VERSION::MAJOR == 6
end