2013-05-27 16:15:17 +02:00
|
|
|
require "rails_big_brother/version"
|
2013-05-28 10:38:20 +02:00
|
|
|
require "rails_big_brother/controller"
|
|
|
|
require "rails_big_brother/model"
|
2013-05-27 16:15:17 +02:00
|
|
|
|
|
|
|
module RailsBigBrother
|
2013-05-29 14:31:50 +02:00
|
|
|
class << self
|
2013-05-29 15:33:52 +02:00
|
|
|
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
|
2013-05-28 12:01:15 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def logger
|
|
|
|
@logger ||= Rails.logger
|
|
|
|
end
|
2013-05-28 12:01:15 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def format
|
|
|
|
@format ||= "big_brother;%<user>s;%<controller_info>s;%<class>s;%<id>s;%<action>s;%<args>s"
|
|
|
|
end
|
2013-05-28 10:38:20 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def configure(&block)
|
|
|
|
yield(self) if block_given?
|
|
|
|
end
|
2013-05-28 10:38:20 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def user=(value)
|
|
|
|
store[:user] = value
|
|
|
|
end
|
2013-05-28 10:38:20 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def user
|
|
|
|
store[:user]
|
|
|
|
end
|
2013-05-28 10:38:20 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def controller_info=(value)
|
|
|
|
store[:controller_info] = value
|
2013-05-28 10:38:20 +02:00
|
|
|
end
|
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def controller_info
|
|
|
|
store[:controller_info]
|
|
|
|
end
|
2013-05-28 10:38:20 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def controller_info_string
|
|
|
|
case controller_info
|
|
|
|
when Array
|
2013-05-29 15:33:52 +02:00
|
|
|
array_to_s.call(controller_info)
|
2013-05-29 14:31:50 +02:00
|
|
|
when Hash
|
2013-05-29 15:33:52 +02:00
|
|
|
hash_to_s.call(controller_info)
|
2013-05-29 14:31:50 +02:00
|
|
|
else
|
|
|
|
controller_info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2013-05-28 10:38:20 +02:00
|
|
|
|
2013-05-29 14:31:50 +02:00
|
|
|
def store
|
|
|
|
Thread.current[:big_brother_log] ||= {}
|
|
|
|
end
|
|
|
|
end
|
2013-05-28 10:38:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
ActiveSupport.on_load(:active_record) do
|
|
|
|
include RailsBigBrother::Model
|
|
|
|
end
|
|
|
|
|
|
|
|
ActiveSupport.on_load(:action_controller) do
|
|
|
|
include RailsBigBrother::Controller
|
2013-05-27 16:15:17 +02:00
|
|
|
end
|