Add hash_to_s and array_to_s options to define proc
parent
a83de02b0f
commit
7b1e4acf48
|
@ -22,6 +22,8 @@ Or install it yourself as:
|
|||
RailsBigBrother.config do |config|
|
||||
config.format = "big_brother;%<user>s;%<controller_info>s;%<class>s;%<id>s;%<action>s;%<args>s"
|
||||
config.logger = Rails.logger
|
||||
config.hash_to_s = proc { |hash| hash.map { |k,v| "#{k}:#{v}" }.join(',') }
|
||||
config.array_to_s = proc { |array| array.join(',') }
|
||||
end
|
||||
```
|
||||
|
||||
|
|
|
@ -4,7 +4,19 @@ require "rails_big_brother/model"
|
|||
|
||||
module RailsBigBrother
|
||||
class << self
|
||||
attr_writer :format, :logger
|
||||
attr_writer :array_to_s, :hash_to_s, :format, :logger
|
||||
|
||||
def array_to_s
|
||||
@array_to_s ||= Proc.new do |array|
|
||||
array.join(',')
|
||||
end
|
||||
end
|
||||
|
||||
def hash_to_s
|
||||
@hash_to_s ||= Proc.new do |hash|
|
||||
hash.map { |k,v| "#{k}:#{v}" }.join(',')
|
||||
end
|
||||
end
|
||||
|
||||
def logger
|
||||
@logger ||= Rails.logger
|
||||
|
@ -37,9 +49,9 @@ module RailsBigBrother
|
|||
def controller_info_string
|
||||
case controller_info
|
||||
when Array
|
||||
controller_info.join(',')
|
||||
array_to_s.call(controller_info)
|
||||
when Hash
|
||||
controller_info.map { |k,v| "#{k}:#{v}" }.join(',')
|
||||
hash_to_s.call(controller_info)
|
||||
else
|
||||
controller_info
|
||||
end
|
||||
|
|
|
@ -34,12 +34,15 @@ 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?
|
||||
changed_fields_string = changed_fields.map do |f|
|
||||
f + (
|
||||
fields_hash = changed_fields.inject({}) do |hash, field|
|
||||
hash[field] = (
|
||||
self.class.big_brother_options.has_key?(:verbose) &&
|
||||
self.class.big_brother_options[:verbose].include?(f) ? ":#{send(f)}" : '')
|
||||
end.join(',')
|
||||
big_brother_log 'update', changed_fields_string
|
||||
self.class.big_brother_options[:verbose].include?(field) ? send(field).to_s : ''
|
||||
)
|
||||
|
||||
hash
|
||||
end
|
||||
big_brother_log 'update', RailsBigBrother.hash_to_s.call(fields_hash)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -55,7 +58,7 @@ module RailsBigBrother
|
|||
class: self.class.name,
|
||||
id: self.to_param,
|
||||
action: action,
|
||||
args: args.join(',')
|
||||
args: RailsBigBrother.array_to_s.call(args)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue