conditional tracking of only/ignore#273
Conversation
|
@razum2um - Thanks for the pull request. I'm trying to merge this but I'm not sure I fully understand the functionality. The purpose of the Looking at your examples that you've added to the README in your commit, can't these same things be accomplished with the Here is the example you provide in the README: class Article < ActiveRecord::Base
has_paper_trail :ignore => [:title, :rating => Proc.new { |obj| obj.rating == 0 } ]
end
> a = Article.create
> a.versions.length #1
> a.update_attributes title: 'My title', rating: 0
> a.versions.length #1
> a.update_attributes title 'A Title', rating: 3
> a.versions.length #2
> a.previous_version.rating #3But couldn't the same behavior be accomplished with the class Article < ActiveRecord::Base
has_paper_trail ignore: :title, unless: Proc.new { |obj| obj.rating == 0 }
endIf I'm not mistaken, this accomplishes the exact same behavior, and actually seems more clear to me. Furthermore, allowing hashes to be passed into the class Article < ActiveRecord::Base
has_paper_trail :ignore => [:title, :rating => Proc.new { |obj| obj.title.blank? } ]
endWhat happens in a scenario like this? If I'm reading the code correctly, it basically means that any changes to I think at the least, in order to merge this, we need to make the examples in the README will need to be expanded and/or clarified to make it a little more clear what this type of thing could be used for, as the current examples you've provided don't really accomplish anything different beyond what could've already been accomplished before this change. |
|
perhaps examples in README are not the best. now achieved by :ignore => [..., :description => Proc.new { |a|
a.description.to_s.gsub(/\W/, '') == a.description_was.to_s.gsub(/\W/, '')
}]but if, unless are model-wide options, if other attribute changed aside of description, version should be created. |
|
@razum2um - Thanks a lot for this! It's a very neat feature, I just didn't fully understand the use case when I originally read the examples, but after playing with it for a while I see that this adds a level of flexibility that wasn't there before. I condensed and cleaned up the code and the examples on the README in 22dd0cc if you want to take a look. |
|
yep, it's much prettier now, thanks |
hi, this patch add some ability to customize only/ignore attributes behaviour