henko 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +12 -0
- data/app/models/henko/audit_log.rb +2 -1
- data/lib/henko.rb +1 -0
- data/lib/henko/log_manager.rb +8 -14
- data/lib/henko/version.rb +1 -1
- data/spec/lib/henko/log_manager_spec.rb +7 -3
- metadata +5 -5
- data/README.rdoc +0 -3
data/Gemfile.lock
CHANGED
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Henko (変更)
|
2
|
+
|
3
|
+
## What does Henko mean?
|
4
|
+
Henko means "change" in japanese
|
5
|
+
|
6
|
+
## What does Henko do?
|
7
|
+
Henko will save an Audit Log on ALL of your AR models automatically.
|
8
|
+
|
9
|
+
Once you include `gem "henko"` in your Gemfile, you don't need to do anything else, Henko will monitor the changes and save everything into your MongoDB database.
|
10
|
+
|
11
|
+
## License
|
12
|
+
see MIT-LICENSE file…
|
data/lib/henko.rb
CHANGED
data/lib/henko/log_manager.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support'
|
1
2
|
module Henko
|
2
3
|
class LogManager
|
3
4
|
cattr_accessor :user_id, :user_ip, :action_url
|
@@ -8,26 +9,19 @@ module Henko
|
|
8
9
|
|
9
10
|
return unless record && options
|
10
11
|
|
11
|
-
changes
|
12
|
+
changes = record.changes.dup
|
12
13
|
current_user_id = Henko::LogManager.user_id
|
13
14
|
|
14
|
-
audit_log
|
15
|
+
audit_log = Henko::AuditLog.new
|
15
16
|
audit_log.class_name = record.class.name
|
16
|
-
audit_log.user_id
|
17
|
-
audit_log.action
|
17
|
+
audit_log.user_id = current_user_id if current_user_id
|
18
|
+
audit_log.action = options[:action]
|
18
19
|
audit_log.action_url = Henko::LogManager.action_url if Henko::LogManager.action_url
|
19
|
-
audit_log.user_ip
|
20
|
+
audit_log.user_ip = Henko::LogManager.user_ip if Henko::LogManager.user_ip
|
20
21
|
|
21
|
-
audit_log.
|
22
|
+
audit_log.model_changes = changes.to_json
|
23
|
+
audit_log.model_snapshot = record.to_json
|
22
24
|
|
23
|
-
if action == 'update'
|
24
|
-
changes.each_key do |key|
|
25
|
-
values= changes[key]
|
26
|
-
prev_value = values[0]
|
27
|
-
new_value = values[1]
|
28
|
-
audit_log.data += "\n\nupdate #{key} from #{prev_value.nil? ? 'NIL' : prev_value} to #{new_value.nil? ? 'NIL' : new_value}\n"
|
29
|
-
end
|
30
|
-
end
|
31
25
|
audit_log.save
|
32
26
|
|
33
27
|
return true
|
data/lib/henko/version.rb
CHANGED
@@ -25,7 +25,9 @@ describe Henko::LogManager do
|
|
25
25
|
subject.action_url = "/some_action"
|
26
26
|
subject.user_ip = "127.0.0.1"
|
27
27
|
|
28
|
-
@user = User.create(first_name: Faker::Name.first_name,
|
28
|
+
@user = User.create(first_name: Faker::Name.first_name,
|
29
|
+
last_name: Faker::Name.last_name,
|
30
|
+
email: Faker::Internet.email)
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should save all data correctly when model is created" do
|
@@ -36,14 +38,16 @@ describe Henko::LogManager do
|
|
36
38
|
audit_log.user_id.should == "1"
|
37
39
|
audit_log.user_ip.should == "127.0.0.1"
|
38
40
|
audit_log.class_name.should == 'User'
|
39
|
-
audit_log.
|
41
|
+
audit_log.model_changes.should include(@user.first_name)
|
42
|
+
audit_log.model_snapshot.should_not be_nil
|
40
43
|
end
|
41
44
|
|
42
45
|
it "should save all data correctly when model is updated" do
|
43
46
|
@user.first_name = "Avi"
|
44
47
|
subject.audit_model({ record: @user, action: 'update' })
|
45
48
|
audit_log = Henko::AuditLog.last
|
46
|
-
audit_log.
|
49
|
+
audit_log.model_changes.should include("Avi")
|
50
|
+
audit_log.model_snapshot.should_not be_nil
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: henko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -231,7 +231,7 @@ files:
|
|
231
231
|
- Gemfile
|
232
232
|
- Gemfile.lock
|
233
233
|
- MIT-LICENSE
|
234
|
-
- README.
|
234
|
+
- README.md
|
235
235
|
- Rakefile
|
236
236
|
- app/assets/images/change_logger/.gitkeep
|
237
237
|
- app/assets/javascripts/change_logger/application.js
|
@@ -305,7 +305,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
305
305
|
version: '0'
|
306
306
|
segments:
|
307
307
|
- 0
|
308
|
-
hash: -
|
308
|
+
hash: -1576474627444299238
|
309
309
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
310
310
|
none: false
|
311
311
|
requirements:
|
@@ -314,7 +314,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
314
314
|
version: '0'
|
315
315
|
segments:
|
316
316
|
- 0
|
317
|
-
hash: -
|
317
|
+
hash: -1576474627444299238
|
318
318
|
requirements: []
|
319
319
|
rubyforge_project:
|
320
320
|
rubygems_version: 1.8.24
|
data/README.rdoc
DELETED