gbdev-acts_as_callback_logger 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/init.rb +14 -6
- data/lib/acts_as_callback_logger.rb +7 -4
- data/lib/callback_logger.rb +17 -15
- data/lib/logger_link_to.rb +50 -0
- data/spec/acts_as_callback_logger_spec.rb +115 -107
- data/spec/logger_link_to_spec.rb +56 -0
- data/spec/spec_helper.rb +112 -8
- metadata +4 -6
- data/spec/database.yml +0 -7
- data/spec/schema.rb +0 -28
data/init.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
require 'active_record'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require File.dirname(__FILE__) + "/lib/acts_as_callback_logger.rb"
|
3
|
+
require File.dirname(__FILE__) + "/lib/callback_logger.rb"
|
4
|
+
require File.dirname(__FILE__) + "/lib/logger_link_to.rb"
|
4
5
|
|
5
|
-
ActiveRecord::Base.class_eval do
|
6
|
-
|
7
|
-
|
8
|
-
end
|
6
|
+
# ActiveRecord::Base.class_eval do
|
7
|
+
# include GBDev::Acts::CallbackLogger
|
8
|
+
# include GBDev::CallbackLogger
|
9
|
+
# end
|
10
|
+
|
11
|
+
#ActionView::Helpers::AssetTagHelper.class_eval do
|
12
|
+
# ActionView::Helpers::TagHelper.class_eval do
|
13
|
+
# include GBDev::CallbackLogger::HelperMethods
|
14
|
+
# end
|
15
|
+
|
16
|
+
#ActionView::Helpers::FormHelper.send(:include, GBDev::CallbackLogger::HelperMethods)
|
@@ -10,10 +10,13 @@ module GBDev #:nodoc:
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module ClassMethods
|
13
|
+
# attr_accessor :callback_text_attr
|
13
14
|
|
14
|
-
def acts_as_callback_logger(
|
15
|
-
options = {:text => 'name'}
|
16
|
-
options.merge!(
|
15
|
+
def acts_as_callback_logger(*args)
|
16
|
+
# options = {:text => 'name', :object_url => {}}
|
17
|
+
# options.merge!(args.pop) unless args.empty?
|
18
|
+
#
|
19
|
+
# self.callback_text_attr = options.delete(:text)
|
17
20
|
|
18
21
|
extend GBDev::Acts::CallbackLogger::SingletonMethods
|
19
22
|
include GBDev::Acts::CallbackLogger::InstanceMethods
|
@@ -97,4 +100,4 @@ module GBDev #:nodoc:
|
|
97
100
|
end # Acts
|
98
101
|
end # GBDev
|
99
102
|
|
100
|
-
ActiveRecord::Base.send
|
103
|
+
ActiveRecord::Base.send(:include, GBDev::Acts::CallbackLogger)
|
data/lib/callback_logger.rb
CHANGED
@@ -8,18 +8,19 @@ module GBDev #:nodoc:
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
attr_accessor :callback_logger_text_attr, :
|
11
|
+
attr_accessor :callback_logger_text_attr, :callback_logger_model, :callback_logger_object_url
|
12
12
|
|
13
|
-
def log_callbacks(
|
14
|
-
options = {:aacl_model => 'AppLog'}
|
15
|
-
options.merge!(
|
13
|
+
def log_callbacks(*args)
|
14
|
+
options = {:text => '', :object_url => {}, :aacl_model => 'AppLog'}
|
15
|
+
options.merge!(args.pop) unless args.empty?
|
16
16
|
|
17
|
-
|
17
|
+
self.callback_logger_text_attr = options.delete(:text).to_sym unless options[:text].blank?
|
18
|
+
self.callback_logger_object_url = options.delete(:object_url)
|
19
|
+
|
20
|
+
mod = options.delete(:aacl_model).titleize.gsub(' ','')
|
18
21
|
mod = ActiveSupport::Inflector.camelize(mod).constantize
|
19
|
-
self.
|
20
|
-
|
21
|
-
self.callback_logger_text_attr = options[:text].to_sym if options.has_key?(:text)
|
22
|
-
|
22
|
+
self.callback_logger_model = mod
|
23
|
+
|
23
24
|
extend GBDev::CallbackLogger::SingletonMethods
|
24
25
|
include GBDev::CallbackLogger::InstanceMethods
|
25
26
|
|
@@ -39,10 +40,11 @@ module GBDev #:nodoc:
|
|
39
40
|
|
40
41
|
module InstanceMethods
|
41
42
|
|
42
|
-
def log_create
|
43
|
+
def log_create
|
44
|
+
data = "id||#{self.id}||#{self.id}|"
|
43
45
|
class_name = self.class.to_s.titleize.downcase
|
44
46
|
msg = "Created #{class_name} (#{text_to_display})"
|
45
|
-
self.class.
|
47
|
+
self.class.callback_logger_model.create({:msg => msg, :data => data, :model => self.class.to_s})
|
46
48
|
rescue Exception => msg
|
47
49
|
# Just fail quietly
|
48
50
|
end
|
@@ -53,7 +55,7 @@ module GBDev #:nodoc:
|
|
53
55
|
|
54
56
|
class_name = self.class.to_s.titleize.downcase
|
55
57
|
msg = "Updated #{class_name} (#{text_to_display})"
|
56
|
-
self.class.
|
58
|
+
self.class.callback_logger_model.create({:msg => msg, :data => data, :model => self.class.to_s}) unless data.empty?
|
57
59
|
rescue Exception => msg
|
58
60
|
# Just fail quietly
|
59
61
|
end
|
@@ -63,7 +65,7 @@ module GBDev #:nodoc:
|
|
63
65
|
|
64
66
|
class_name = self.class.to_s.titleize.downcase
|
65
67
|
msg = "Deleted #{class_name} (#{text_to_display})"
|
66
|
-
self.class.
|
68
|
+
self.class.callback_logger_model.create({:msg => msg, :data => data, :model => self.class.to_s})
|
67
69
|
rescue Exception => msg
|
68
70
|
# Just fail quietly
|
69
71
|
end
|
@@ -72,11 +74,11 @@ module GBDev #:nodoc:
|
|
72
74
|
private
|
73
75
|
|
74
76
|
def text_to_display
|
75
|
-
self.class.callback_logger_text_attr.
|
77
|
+
self.class.callback_logger_text_attr.blank? ? self.id : self.send(self.class.callback_logger_text_attr)
|
76
78
|
end
|
77
79
|
end # InstanceMethods
|
78
80
|
|
79
81
|
end # CallbackLogger
|
80
82
|
end # GBDev
|
81
83
|
|
82
|
-
ActiveRecord::Base.send
|
84
|
+
ActiveRecord::Base.send(:include, GBDev::CallbackLogger)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support'
|
3
|
+
#require 'action_view'
|
4
|
+
|
5
|
+
module ActionView::Helpers::AssetTagHelper
|
6
|
+
# module GBDev #:nodoc:
|
7
|
+
# module CallbackLogger #:nodoc:
|
8
|
+
# module HelperMethods #:nodoc:
|
9
|
+
|
10
|
+
def callback_logger_link_to(app_log_object)
|
11
|
+
# TODO: add object checker stuff here....
|
12
|
+
|
13
|
+
# Get model updated in the transaction
|
14
|
+
model = ActiveSupport::Inflector.singularize(app_log_object.model)
|
15
|
+
model = ActiveSupport::Inflector.camelize(model).constantize
|
16
|
+
# obj = model.find(obj_id)
|
17
|
+
return app_log_object.msg if model.callback_logger_object_url.blank?
|
18
|
+
|
19
|
+
# Get stuff within parentheses. It will be the second match.
|
20
|
+
regex = Regexp.new('\((.+)\)$')
|
21
|
+
matches = regex.match(app_log_object.msg)
|
22
|
+
return app_log_object.msg if matches.nil?
|
23
|
+
|
24
|
+
# matches[1] contains the content within the parentheses.
|
25
|
+
content = matches[1]
|
26
|
+
|
27
|
+
# Get the id for this entry
|
28
|
+
regex = Regexp.new('^id\|\|(\d+)\|\|') # String: id||176028860||176028860|::|updated_at||....
|
29
|
+
matches = regex.match(app_log_object.data)
|
30
|
+
return app_log_object.msg if matches.nil?
|
31
|
+
|
32
|
+
# matches[1] contains the content within the parentheses.
|
33
|
+
obj_id = matches[1]
|
34
|
+
|
35
|
+
# Add the id to the url. There should probably be a
|
36
|
+
# check whether or not to include it.
|
37
|
+
# TODO: ....
|
38
|
+
model.callback_logger_object_url.merge!({:id => obj_id})
|
39
|
+
|
40
|
+
app_log_object.msg.gsub(content, link_to(content, model.callback_logger_object_url))
|
41
|
+
end
|
42
|
+
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
|
48
|
+
# module ActionView::Helpers::AssetTagHelper
|
49
|
+
# include GBDev::CallbackLogger::HelperMethods
|
50
|
+
# end
|
@@ -1,107 +1,115 @@
|
|
1
|
-
#!/usr/bin/env ruby -w
|
2
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
3
|
-
|
4
|
-
if Object.const_defined?(:ActiveRecord) and Object.const_defined?(:Mocha) and Object.const_defined?(:Spec)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
1
|
+
# #!/usr/bin/env ruby -w
|
2
|
+
# require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
3
|
+
#
|
4
|
+
# if Object.const_defined?(:ActiveRecord) and Object.const_defined?(:Mocha) and Object.const_defined?(:Spec)
|
5
|
+
#
|
6
|
+
# class AppLog < ActiveRecord::Base
|
7
|
+
# acts_as_callback_logger
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# class Program < ActiveRecord::Base
|
11
|
+
# log_callbacks :text => 'name'
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# class GroupType < ActiveRecord::Base
|
15
|
+
# log_callbacks :text => 'name'#, :object_url => {:controller => 'clients/charges', :action => 'edit'}
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
#
|
19
|
+
# describe 'CallbackLogger' do
|
20
|
+
#
|
21
|
+
# before(:each) do
|
22
|
+
# build_database_connection
|
23
|
+
# InitialSchema.up
|
24
|
+
#
|
25
|
+
# AppLog.delete_all
|
26
|
+
# Program.delete_all
|
27
|
+
# GroupType.delete_all
|
28
|
+
# @program = Program.new({:name => 'Some Program'})
|
29
|
+
# @group_type = GroupType.new({:name => 'Some Group Type'})
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# after(:each) do
|
33
|
+
# InitialSchema.down
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# describe 'AppLog' do
|
37
|
+
#
|
38
|
+
# it 'should not have any logs in it to start' do
|
39
|
+
# AppLog.count.should be_zero
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# it 'should undo the program name change' do
|
43
|
+
# @program.save.should be_true
|
44
|
+
# program_id = @program.id
|
45
|
+
#
|
46
|
+
# AppLog.count.should == 1
|
47
|
+
# msg = "Created program (Some Program)"
|
48
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
49
|
+
#
|
50
|
+
# @program.name = 'Dog Man'
|
51
|
+
# @program.save.should be_true
|
52
|
+
# AppLog.count.should == 2
|
53
|
+
# msg = "Updated program (Dog Man)"
|
54
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
55
|
+
#
|
56
|
+
# app_log = AppLog.find_by_msg(msg)
|
57
|
+
# app_log.undo.should be_true
|
58
|
+
# app_log.restored_at.should_not be_nil
|
59
|
+
#
|
60
|
+
# program = Program.find(program_id)
|
61
|
+
# program.name.should == 'Some Program'
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# it 'should undo the group type deletion' do
|
65
|
+
# @group_type.save.should be_true
|
66
|
+
#
|
67
|
+
# group_type_id = @group_type.id
|
68
|
+
#
|
69
|
+
# AppLog.count.should == 1
|
70
|
+
# msg = "Created group type (#{@group_type.name})"
|
71
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
72
|
+
#
|
73
|
+
# @group_type.destroy
|
74
|
+
# GroupType.count.should == 0
|
75
|
+
# msg = "Deleted group type (#{@group_type.name})"
|
76
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
77
|
+
#
|
78
|
+
# app_log = AppLog.find_by_msg("Deleted group type (#{@group_type.name})")
|
79
|
+
# app_log.undo.should be_true
|
80
|
+
# app_log.restored_at.should_not be_nil
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# describe 'Models watched' do
|
85
|
+
# it 'should add a created, updated and deleted entries to the app_logs table' do
|
86
|
+
# @program.save.should be_true
|
87
|
+
# program_id = @program.id
|
88
|
+
# AppLog.count.should == 1
|
89
|
+
# msg = "Created program (Some Program)"
|
90
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
91
|
+
#
|
92
|
+
# @group_type.save.should be_true
|
93
|
+
# group_type_id = @group_type.id
|
94
|
+
# AppLog.count.should == 2
|
95
|
+
# msg = "Created group type (#{@group_type.name})"
|
96
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
97
|
+
#
|
98
|
+
# @program.name = 'Dog Man'
|
99
|
+
# @program.save.should be_true
|
100
|
+
# AppLog.count.should == 3
|
101
|
+
# msg = "Updated program (Dog Man)"
|
102
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
103
|
+
#
|
104
|
+
# @group_type.destroy
|
105
|
+
# AppLog.count.should == 4
|
106
|
+
# msg = "Deleted group type (#{@group_type.name})"
|
107
|
+
# AppLog.count(:conditions => ["msg = ?", msg]).should == 1
|
108
|
+
# end
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# else
|
114
|
+
# $stderr.puts "Warning: ActiveRecord, Spec or Mocha not found -- skipping AAR tests"
|
115
|
+
# end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
3
|
+
|
4
|
+
if Object.const_defined?(:ActiveRecord) and Object.const_defined?(:Mocha) and Object.const_defined?(:Spec)
|
5
|
+
|
6
|
+
class AppLog < ActiveRecord::Base
|
7
|
+
acts_as_callback_logger
|
8
|
+
end
|
9
|
+
|
10
|
+
class Event < ActiveRecord::Base
|
11
|
+
log_callbacks :text => 'name'
|
12
|
+
end
|
13
|
+
|
14
|
+
class Charge < ActiveRecord::Base
|
15
|
+
log_callbacks :text => 'name'#, :object_url => {:controller => 'clients/charges', :action => 'edit'}
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
describe 'GBDev::CallbackLogger::HelperMethods' do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
build_database_connection
|
23
|
+
InitialSchema.up
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:each) do
|
27
|
+
build_database_connection
|
28
|
+
InitialSchema.down
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'logger_link_to' do
|
32
|
+
it "should not be a link since :object_url is not set" do
|
33
|
+
AppLog.delete_all
|
34
|
+
Event.delete_all
|
35
|
+
event = Event.new({:name => 'Some Event'})
|
36
|
+
event.save.should be_true
|
37
|
+
log = AppLog.find(:first)
|
38
|
+
logger_link_to(log).should == "Created event (Some Event)"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# describe 'logger_link_to' do
|
43
|
+
# it "should build a link in the message between the parentheses" do
|
44
|
+
# AppLog.delete_all
|
45
|
+
# Charge.delete_all
|
46
|
+
# charge = Charge.new({:name => 'Some Charge'})
|
47
|
+
# charge.save.should be_true
|
48
|
+
# log = AppLog.find(:first)
|
49
|
+
# logger_link_to(log).should match(/Created charge \(<a href.*\/clients\/charges\/edit.*>Some Charge<\/a>\)/)
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
end
|
53
|
+
|
54
|
+
else
|
55
|
+
$stderr.puts "Warning: ActiveRecord, Spec or Mocha not found -- skipping AAR tests"
|
56
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,123 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
PLUGIN_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
1
4
|
require 'rubygems'
|
2
5
|
require 'ruby-debug'
|
3
6
|
require 'active_record'
|
4
|
-
require '
|
7
|
+
require 'active_support'
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_view'
|
10
|
+
require 'rexml/document'
|
11
|
+
require 'html/document'
|
5
12
|
require 'mocha'
|
13
|
+
require 'spec'
|
14
|
+
|
15
|
+
require File.join(PLUGIN_ROOT, 'lib/acts_as_callback_logger')
|
16
|
+
require File.join(PLUGIN_ROOT, 'lib/callback_logger')
|
17
|
+
require File.join(PLUGIN_ROOT, 'lib/logger_link_to')
|
18
|
+
|
19
|
+
include ActionView::Helpers::UrlHelper
|
20
|
+
include ActionController::UrlWriter
|
21
|
+
include ActionView::Helpers::AssetTagHelper
|
6
22
|
|
7
|
-
|
8
|
-
|
23
|
+
#include GBDev::Acts::CallbackLogger
|
24
|
+
#include GBDev::CallbackLogger
|
25
|
+
#include GBDev::CallbackLogger::HelperMethods
|
9
26
|
|
10
|
-
|
11
|
-
|
27
|
+
# config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
28
|
+
# ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
29
|
+
# ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'postgresql'])
|
12
30
|
|
13
|
-
|
14
|
-
|
15
|
-
|
31
|
+
ActionController::UrlWriter.default_url_options = {:host => 'localhost'}
|
32
|
+
ActionController::Routing::Routes.draw do |map|
|
33
|
+
map.connect ':controller/:action/:id'
|
34
|
+
map.connect ':controller/:action/:id.:format'
|
35
|
+
end
|
16
36
|
|
17
37
|
load(File.dirname(__FILE__) + '/schema.rb') if File.exist?(File.dirname(__FILE__) + '/schema.rb')
|
38
|
+
|
39
|
+
#ActionView::Helpers::AssetTagHelper.send :include, GBDev::CallbackLogger::HelperMethods
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
class InitialSchema < ActiveRecord::Migration
|
46
|
+
|
47
|
+
def self.up
|
48
|
+
create_table :app_logs do |t|
|
49
|
+
t.column :msg, :string, :null => false
|
50
|
+
t.column :data, :text
|
51
|
+
t.column :model, :text
|
52
|
+
t.column :restored_at, :datetime
|
53
|
+
t.column :created_at, :datetime
|
54
|
+
end
|
55
|
+
|
56
|
+
create_table :events do |t|
|
57
|
+
t.column :name, :string, :limit => 255
|
58
|
+
end
|
59
|
+
|
60
|
+
create_table :charges do |t|
|
61
|
+
t.column :name, :string, :limit => 255
|
62
|
+
end
|
63
|
+
|
64
|
+
create_table :programs do |t|
|
65
|
+
t.column :name, :string, :limit => 255
|
66
|
+
end
|
67
|
+
|
68
|
+
create_table :group_types do |t|
|
69
|
+
t.column :name, :string, :limit => 255
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.down
|
74
|
+
drop_table :app_logs
|
75
|
+
drop_table :events
|
76
|
+
drop_table :charges
|
77
|
+
drop_table :programs
|
78
|
+
drop_table :group_types
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def create_sqlite3_connection
|
85
|
+
ActiveRecord::Base.establish_connection(
|
86
|
+
:adapter => "sqlite3",
|
87
|
+
:dbfile => ":memory:"
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
def create_postgresql_connection
|
92
|
+
ActiveRecord::Base.establish_connection(
|
93
|
+
:adapter => "postgresql",
|
94
|
+
:host => "localhost",
|
95
|
+
:username => "aacl",
|
96
|
+
:password => "aacl",
|
97
|
+
:database => "acts_as_callback_logger"
|
98
|
+
)
|
99
|
+
end
|
18
100
|
|
101
|
+
def create_mysql_connection
|
102
|
+
# '/tmp/mysql.sock' is the default location and file rails looks for.
|
103
|
+
mysql_socket = ENV['MYSQLSOCKET'].nil? ? '/tmp/mysql.sock' : ENV['MYSQLSOCKET']
|
104
|
+
ActiveRecord::Base.establish_connection(
|
105
|
+
:adapter => "mysql",
|
106
|
+
:host => "localhost",
|
107
|
+
:username => "aacl",
|
108
|
+
:password => "aacl",
|
109
|
+
:database => "acts_as_callback_logger",
|
110
|
+
:socket => mysql_socket
|
111
|
+
)
|
112
|
+
end
|
19
113
|
|
114
|
+
def build_database_connection
|
115
|
+
case ENV['DATABASE']
|
116
|
+
when 'mysql'
|
117
|
+
create_mysql_connection
|
118
|
+
when 'postgresql'
|
119
|
+
create_postgresql_connection
|
120
|
+
else 'sqlite3'
|
121
|
+
create_sqlite3_connection
|
122
|
+
end
|
123
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gbdev-acts_as_callback_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wes Hays
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-
|
13
|
+
date: 2008-12-05 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -32,9 +32,9 @@ files:
|
|
32
32
|
- uninstall.rb
|
33
33
|
- lib/acts_as_callback_logger.rb
|
34
34
|
- lib/callback_logger.rb
|
35
|
+
- lib/logger_link_to.rb
|
35
36
|
- spec/acts_as_callback_logger_spec.rb
|
36
|
-
- spec/
|
37
|
-
- spec/schema.rb
|
37
|
+
- spec/logger_link_to_spec.rb
|
38
38
|
- spec/spec_helper.rb
|
39
39
|
- tasks/acts_as_callback_logger_tasks.rake
|
40
40
|
has_rdoc: false
|
@@ -65,6 +65,4 @@ specification_version: 2
|
|
65
65
|
summary: Rails gem/plugin to log callback events (after_create, after_update, after_destroy) for certain models tracking various things that users did within the application.
|
66
66
|
test_files:
|
67
67
|
- spec/acts_as_callback_logger_spec.rb
|
68
|
-
- spec/database.yml
|
69
|
-
- spec/schema.rb
|
70
68
|
- spec/spec_helper.rb
|
data/spec/database.yml
DELETED
data/spec/schema.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define(:version => 1) do
|
2
|
-
|
3
|
-
begin
|
4
|
-
execute 'DROP TABLE app_logs'
|
5
|
-
execute 'DROP TABLE programs'
|
6
|
-
execute 'DROP TABLE group_types'
|
7
|
-
rescue
|
8
|
-
# Do nothing because this is the first time this script has ran so
|
9
|
-
# the tables did not exist yet. Thus is why the error was thrown.
|
10
|
-
end
|
11
|
-
|
12
|
-
create_table :app_logs do |t|
|
13
|
-
t.column :msg, :string, :null => false
|
14
|
-
t.column :data, :text
|
15
|
-
t.column :model, :text
|
16
|
-
t.column :restored_at, :datetime
|
17
|
-
t.column :created_at, :datetime
|
18
|
-
end
|
19
|
-
|
20
|
-
create_table :programs do |t|
|
21
|
-
t.column :name, :string, :limit => 255
|
22
|
-
end
|
23
|
-
|
24
|
-
create_table :group_types do |t|
|
25
|
-
t.column :name, :string, :limit => 255
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|