henko 1.0.0 → 1.1.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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- henko (1.0.0)
4
+ henko (1.1.0)
5
5
  bson_ext (~> 1.5)
6
6
  mongoid (~> 2.4)
7
7
  rails (~> 3.2.6)
@@ -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…
@@ -8,7 +8,8 @@ module Henko
8
8
  field :class_name, type: String
9
9
  field :user_ip, type: String
10
10
 
11
- field :data, type: String
11
+ field :model_changes, type: String
12
+ field :model_snapshot, type: String
12
13
 
13
14
  index :user_id, sparse: true
14
15
  index :action
@@ -2,6 +2,7 @@ require "henko/engine"
2
2
  require 'henko'
3
3
 
4
4
  module Henko
5
+
5
6
  end
6
7
 
7
8
  require 'henko/active_record_extensions'
@@ -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 = record.changes
12
+ changes = record.changes.dup
12
13
  current_user_id = Henko::LogManager.user_id
13
14
 
14
- audit_log = Henko::AuditLog.new
15
+ audit_log = Henko::AuditLog.new
15
16
  audit_log.class_name = record.class.name
16
- audit_log.user_id = current_user_id if current_user_id
17
- audit_log.action = options[: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 = Henko::LogManager.user_ip if Henko::LogManager.user_ip
20
+ audit_log.user_ip = Henko::LogManager.user_ip if Henko::LogManager.user_ip
20
21
 
21
- audit_log.data = changes.to_json
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
@@ -1,3 +1,3 @@
1
1
  module Henko
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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, last_name: Faker::Name.last_name, email: Faker::Internet.email)
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.data.should include(@user.first_name)
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.data.should include("Avi")
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.0.0
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 00:00:00.000000000 Z
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.rdoc
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: -4001270427597017019
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: -4001270427597017019
317
+ hash: -1576474627444299238
318
318
  requirements: []
319
319
  rubyforge_project:
320
320
  rubygems_version: 1.8.24
@@ -1,3 +0,0 @@
1
- = Henko
2
-
3
- This project rocks and uses MIT-LICENSE.