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|
|
RailsBigBrother.config do |config|
|
||||||
config.format = "big_brother;%<user>s;%<controller_info>s;%<class>s;%<id>s;%<action>s;%<args>s"
|
config.format = "big_brother;%<user>s;%<controller_info>s;%<class>s;%<id>s;%<action>s;%<args>s"
|
||||||
config.logger = Rails.logger
|
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
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,19 @@ require "rails_big_brother/model"
|
||||||
|
|
||||||
module RailsBigBrother
|
module RailsBigBrother
|
||||||
class << self
|
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
|
def logger
|
||||||
@logger ||= Rails.logger
|
@logger ||= Rails.logger
|
||||||
|
@ -37,9 +49,9 @@ module RailsBigBrother
|
||||||
def controller_info_string
|
def controller_info_string
|
||||||
case controller_info
|
case controller_info
|
||||||
when Array
|
when Array
|
||||||
controller_info.join(',')
|
array_to_s.call(controller_info)
|
||||||
when Hash
|
when Hash
|
||||||
controller_info.map { |k,v| "#{k}:#{v}" }.join(',')
|
hash_to_s.call(controller_info)
|
||||||
else
|
else
|
||||||
controller_info
|
controller_info
|
||||||
end
|
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)
|
changed_fields = changed_fields & self.class.big_brother_options[:only] if self.class.big_brother_options.has_key?(:only)
|
||||||
|
|
||||||
unless changed_fields.empty?
|
unless changed_fields.empty?
|
||||||
changed_fields_string = changed_fields.map do |f|
|
fields_hash = changed_fields.inject({}) do |hash, field|
|
||||||
f + (
|
hash[field] = (
|
||||||
self.class.big_brother_options.has_key?(:verbose) &&
|
self.class.big_brother_options.has_key?(:verbose) &&
|
||||||
self.class.big_brother_options[:verbose].include?(f) ? ":#{send(f)}" : '')
|
self.class.big_brother_options[:verbose].include?(field) ? send(field).to_s : ''
|
||||||
end.join(',')
|
)
|
||||||
big_brother_log 'update', changed_fields_string
|
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
big_brother_log 'update', RailsBigBrother.hash_to_s.call(fields_hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +58,7 @@ module RailsBigBrother
|
||||||
class: self.class.name,
|
class: self.class.name,
|
||||||
id: self.to_param,
|
id: self.to_param,
|
||||||
action: action,
|
action: action,
|
||||||
args: args.join(',')
|
args: RailsBigBrother.array_to_s.call(args)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue