rack-action_logger 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c8a0cd101f204c4b4e28255d03d14e870cba315
4
- data.tar.gz: e0f07f6e7cea35b0ec48eb914df791a8676ed3e6
3
+ metadata.gz: cdf281bb433975f9e1ae3f5094d33d4e148edf0b
4
+ data.tar.gz: 2131e546b68052279361b06d3000ea6b39f0e9d0
5
5
  SHA512:
6
- metadata.gz: 552f8b621a8668c9b39526f74839045f2671dd6ab9891e2bc6bdb063067093392258bfe03ffc5784f5a9052be45c8986ee89d15717d2aa483ea6bba8076ca1db
7
- data.tar.gz: 34f8be1a577fda8469a585e07fbf8b482f6abefadc1a21c14a602b70e7fd04214658b8705467d33e86135129bad699b07ddbccbb2bf484f1808da00bd9f2a033
6
+ metadata.gz: 33d969ec2ba81f9a0e356e27857ceb9e2a8e1eb3550f672db7bfd1a8fae1b4a174f3d452f0ea7fd0e9d2a58b8c2060e33b85209c5ed36bc3d719562ca69d7dc1
7
+ data.tar.gz: c9734aefd64c3f42d68ffc4c5cdc71c7e058700021186a456ae3ece25f2965624333c95c746a90490c71512c32f5e8d21302974e5c3b6d0684eb8aa43e9dbf25
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-action_logger (0.1.5)
4
+ rack-action_logger (0.1.6)
5
5
  activesupport
6
6
  fluent-logger (~> 0.5)
7
7
  woothee (~> 1.4)
data/README.md CHANGED
@@ -129,6 +129,14 @@ Add the following code to any code on any times.
129
129
  Rack::ActionLogger::Container.set_append_log({ value: 'ok' }, 'activities')
130
130
  ```
131
131
 
132
+ ### Add Model Logger
133
+
134
+ Add the folloing line to ```config/initializers/rack-action_logger.rb``` at the end of line.
135
+
136
+ ```
137
+ ActiveRecord::Base.send(:include, Rack::ActionLog::ActiveRecordExtension)
138
+ ```
139
+
132
140
  ### Override log attributes
133
141
 
134
142
  Overriden attributes are added to both request and append logs.
@@ -0,0 +1,45 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+
4
+ module Rack::ActionLogger
5
+ module ActiveRecordExtension
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ after_create :capture_action_log_create
10
+ after_update :capture_action_log_update
11
+ after_destroy :capture_action_log_destroy
12
+ end
13
+
14
+ def capture_action_log_create
15
+ record = { _method: 'create' }
16
+ self.class.column_names.each do |column_name|
17
+ record["_#{column_name}"] = self.try(column_name)
18
+ end
19
+ Rack::ActionLogger::Container.set_append_log(record, "model_#{self.class.table_name}")
20
+ end
21
+
22
+ def capture_action_log_update
23
+ record = { _method: 'update' }
24
+ self.class.column_names.each do |column_name|
25
+ if column_name.end_with?('_id')
26
+ record["_#{column_name}"] = self.try(column_name)
27
+ elsif self.try("#{column_name}_changed?")
28
+ record["_after:#{column_name}"] = self.try(column_name)
29
+ record["_before:#{column_name}"] = self.try("#{column_name}_was")
30
+ end
31
+ end
32
+ Rack::ActionLogger::Container.set_append_log(record, "model_#{self.class.table_name}")
33
+ end
34
+
35
+ def capture_action_log_destroy
36
+ record = { _method: 'delete' }
37
+ self.class.column_names.each do |column_name|
38
+ if column_name == 'id' || column_name.end_with?('_id')
39
+ record["_#{column_name}"] = self.try(column_name)
40
+ end
41
+ end
42
+ Rack::ActionLogger::Container.set_append_log(record, "model_#{self.class.table_name}")
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module ActionLogger
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-action_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Ishida
@@ -128,6 +128,7 @@ files:
128
128
  - bin/rspec
129
129
  - bin/setup
130
130
  - lib/rack/action_logger.rb
131
+ - lib/rack/action_logger/active_record_extension.rb
131
132
  - lib/rack/action_logger/configuration.rb
132
133
  - lib/rack/action_logger/container.rb
133
134
  - lib/rack/action_logger/context.rb