-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c7a1c3
commit 7a79f24
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module OutdatedAttributes | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def mark_as_outdated(*attributes) | ||
@outdated_attributes = Set.new(attributes.map(&:to_s)) | ||
rewrite_outdated_getters | ||
rewrite_outdated_setters | ||
end | ||
|
||
def outdated_attributes | ||
@outdated_attributes || Set.new | ||
end | ||
|
||
def rewrite_outdated_getters | ||
outdated_attributes.each do |attribute| | ||
define_method attribute.to_s do | ||
raise "Attribute #{attribute} for class '#{self.class}' was marked as outdated" | ||
end | ||
end | ||
end | ||
|
||
def rewrite_outdated_setters | ||
outdated_attributes.each do |attribute| | ||
define_method "#{attribute}=" do |_value| | ||
raise "Attribute #{attribute} for class '#{self.class}' was marked as outdated" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
class ActiveRecord::Base | ||
include OutdatedAttributes | ||
end |