Add 'verbose' option to add attributes value in log
parent
d3dfbb8298
commit
abd0cce54a
|
@ -60,6 +60,15 @@ class Example < ActiveRecord::Base
|
|||
end
|
||||
```
|
||||
|
||||
### Log attributes new value on update
|
||||
|
||||
You can choose to log the new value of an updated field with `verbose` :
|
||||
```ruby
|
||||
class Example < ActiveRecord::Base
|
||||
big_brother_watch verbose: :third
|
||||
end
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it
|
||||
|
|
|
@ -11,7 +11,7 @@ module RailsBigBrother
|
|||
class_attribute :big_brother_options
|
||||
self.big_brother_options = {}
|
||||
|
||||
[:ignore, :only].each do |k|
|
||||
[:ignore, :only, :verbose].each do |k|
|
||||
self.big_brother_options[k] = [options[k]].flatten.compact.map(&:to_s) if options.has_key?(k)
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,11 @@ module RailsBigBrother
|
|||
changed_fields = changed_fields & self.class.big_brother_options[:only] if self.class.big_brother_options.has_key?(:only)
|
||||
|
||||
unless changed_fields.empty?
|
||||
big_brother_log 'update', changed_fields.join(',')
|
||||
changed_fields_string = changed_fields.map do |f|
|
||||
f + (
|
||||
self.class.big_brother_options[:verbose].include?(f) ? ":#{send(f)}" : '')
|
||||
end.join(',')
|
||||
big_brother_log 'update', changed_fields_string
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue