Skip to content
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
2 changes: 1 addition & 1 deletion activerecord-delay_touching.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "activerecord", "~> 4.2"
spec.add_dependency "activerecord", ">= 4.2", "< 5.3"

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
Expand Down
19 changes: 14 additions & 5 deletions lib/activerecord/delay_touching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module DelayTouching
extend ActiveSupport::Concern

# Override ActiveRecord::Base#touch.
def touch(*names)
# see https://github.com/godaddy/activerecord-delay_touching/pull/21 for Rails 5 support
def touch(*names, time: nil)
if self.class.delay_touching? && !try(:no_touching?)
DelayTouching.add_record(self, *names)
true
Expand Down Expand Up @@ -88,10 +89,8 @@ def self.touch_records(attr, klass, records)
records.each do |record|
# Don't bother if destroyed or not-saved
next unless record.persisted?
record.instance_eval do
write_attribute column, current_time
@changed_attributes.except!(*changes.keys)
end
record.send(:write_attribute, column, current_time)
clear_attribute_changes(record, changes.keys)
end
end

Expand All @@ -100,6 +99,16 @@ def self.touch_records(attr, klass, records)
state.updated attr, records
records.each { |record| record.run_callbacks(:touch) }
end

if ActiveRecord::VERSION::MAJOR >= 5
def self.clear_attribute_changes(record, attr_names)
record.clear_attribute_changes(attr_names)
end
else
def self.clear_attribute_changes(record, attr_names)
record.instance_variable_get('@changed_attributes').except!(*attr_names)
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/activerecord/delay_touching/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Activerecord
module DelayTouching
VERSION = "1.1.0"
VERSION = "1.1.1"
end
end