Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match Rails dirty tracking behavior #105

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/active_remote/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ def initialize(attributes = {})
super
@new_record = true

skip_dirty_tracking do
run_callbacks :initialize do
yield self if block_given?
end
run_callbacks :initialize do
yield self if block_given?
end
end

Expand Down
32 changes: 0 additions & 32 deletions lib/active_remote/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ module Dirty

included do
include ActiveModel::Dirty

attr_accessor :_active_remote_track_changes
end

def disable_dirty_tracking
@_active_remote_track_changes = false
end

def enable_dirty_tracking
@_active_remote_track_changes = true
end

# Override #reload to provide dirty tracking.
Expand Down Expand Up @@ -54,30 +44,8 @@ def save!(*)
end
end

def skip_dirty_tracking
disable_dirty_tracking

yield

enable_dirty_tracking
end

private

# Wether or not changes are currently being tracked for this class.
#
def _active_remote_track_changes?
@_active_remote_track_changes != false
end

# Override ActiveAttr's attribute= method so we can provide support for
# ActiveModel::Dirty.
#
def attribute=(name, value)
send(:"#{name}_will_change!") if _active_remote_track_changes? && value != self[name]
super
end

# Override #update to only send changed attributes.
#
def remote_update(*)
Expand Down
Loading