models_auditor 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +112 -0
- data/lib/models_auditor/version.rb +1 -1
- data/lib/tasks/models_auditor_tasks.rake +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48a7e08268e6af1064f7f77660ede51f8f5dca9d
|
4
|
+
data.tar.gz: 4fc60442b137cb0b2020791bd071b53db36c5213
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d862f438b570336df4796b99cecf60f4d3136633c5cc33239c15ff4bcf62ef36425df3915940e5f37d9cdb14209f50c97482f8b846f80e765dcb318ee1187f4
|
7
|
+
data.tar.gz: b8bfbc137c0f5ac1cbf136c81d2a45643149c44aa7339db40647ec6d2fdd7a2df2a1bb0ed559a46f0ce561d92fd2294aa3ff1d1acb0694a96d38edbca3b1aad9
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# ModelsAuditor
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
1. **Add ModelsAuditor to your Gemfile**
|
6
|
+
|
7
|
+
`gem 'models_auditor'`
|
8
|
+
|
9
|
+
Then execute `$ bundle install`
|
10
|
+
|
11
|
+
2. **Add the gem settings to your project**
|
12
|
+
|
13
|
+
`rails g models_auditor:install`
|
14
|
+
|
15
|
+
It added _models_auditor_ initializer. Make necessary settings in this file.
|
16
|
+
|
17
|
+
3. **Generate the audit database config**
|
18
|
+
|
19
|
+
`rails g models_auditor:db_config`
|
20
|
+
|
21
|
+
It appended separate sections to config/database.yml. Edit them.
|
22
|
+
|
23
|
+
4. **Create the audit database**
|
24
|
+
|
25
|
+
`rake db:audit:create`
|
26
|
+
|
27
|
+
5. **Generate models_auditor migrations for audit_database**
|
28
|
+
|
29
|
+
`rails g models_auditor:migrations`
|
30
|
+
|
31
|
+
Migration files will be putted into db/audit_migrate.
|
32
|
+
|
33
|
+
6. **Apply migrations to the audit database**
|
34
|
+
|
35
|
+
`rake db:audit:migrate`
|
36
|
+
|
37
|
+
## Usages
|
38
|
+
|
39
|
+
1. Mount the route for read logs json api
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Rails.application.routes.draw do
|
43
|
+
|
44
|
+
mount ModelsAuditor::Engine => '/audit'
|
45
|
+
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
To looking at routes list do
|
50
|
+
|
51
|
+
`$ rake routes`
|
52
|
+
|
53
|
+
models_auditor_requests GET (/index)(/page/:page)(.:format) models_auditor/audit#index {:page=>/\d+/}
|
54
|
+
root GET / models_auditor/audit#index
|
55
|
+
|
56
|
+
2. To enable audit you have to add into each logged models
|
57
|
+
|
58
|
+
`enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON`
|
59
|
+
|
60
|
+
AUDIT_MODE_JSON - Serialization by #as_json
|
61
|
+
AUDIT_MODE_SERIALIZER - Serialization by using a ActiveModel Serializer, specifyied by :serializer option
|
62
|
+
AUDIT_MODE_METHOD - Serialization by a method, specifyied by :method option
|
63
|
+
AUDIT_MODE_CHANGES_ONLY - Serialization ActiveRecord changes of model only
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
class Post < ActiveRecord::Base
|
67
|
+
enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
class Author < ActiveRecord::Base
|
73
|
+
enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
3. Add to each association models
|
78
|
+
|
79
|
+
`enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON, bridge: {Author.name => :author_id, Post.name => :post_id}`
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class AuthorsPost < ActiveRecord::Base
|
83
|
+
enable_audit ModelsAuditor::Audit::AUDIT_MODE_JSON, bridge: {Author.name => :author_id, Post.name => :post_id}
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
## Audit database management
|
88
|
+
|
89
|
+
**Creation of the audit database**
|
90
|
+
|
91
|
+
`rake db:audit:create`
|
92
|
+
|
93
|
+
**Dropping of the audit database**
|
94
|
+
|
95
|
+
`rake db:audit:drop`
|
96
|
+
|
97
|
+
**Apply migrations to the audit database**
|
98
|
+
|
99
|
+
`rake db:audit:migrate`
|
100
|
+
|
101
|
+
**Rollback migrations to the audit database**
|
102
|
+
|
103
|
+
`rake db:audit:rollback`
|
104
|
+
|
105
|
+
---
|
106
|
+
|
107
|
+
If you want to use a database prefix not from config. You may specify it as an argument in square brackets.
|
108
|
+
|
109
|
+
`rake db:audit:create[audit_shmaudit]`
|
110
|
+
|
111
|
+
|
112
|
+
This project rocks and uses MIT-LICENSE.
|
@@ -9,7 +9,7 @@ namespace :db do
|
|
9
9
|
raise ArgumentError.new('Required parameter [<database>] was not passed') if db.blank?
|
10
10
|
|
11
11
|
connection_params =
|
12
|
-
ActiveRecord::Base.configurations[db].merge(
|
12
|
+
ActiveRecord::Base.configurations[db.to_s].merge(
|
13
13
|
'database' => 'postgres',
|
14
14
|
'schema_search_path' => 'public'
|
15
15
|
)
|
@@ -20,7 +20,7 @@ namespace :db do
|
|
20
20
|
db = args.database || [ModelsAuditor.config.connection_namespace, Rails.env].map(&:presence).compact.join('_').to_sym
|
21
21
|
raise ArgumentError.new('Required parameter [<database>] was not passed') if db.blank?
|
22
22
|
|
23
|
-
connection_params = ActiveRecord::Base.configurations[db]
|
23
|
+
connection_params = ActiveRecord::Base.configurations[db.to_s]
|
24
24
|
ActiveRecord::Base.establish_connection(connection_params)
|
25
25
|
end
|
26
26
|
|
@@ -28,7 +28,7 @@ namespace :db do
|
|
28
28
|
task :create, [:database] => [:connect_without_db, :environment] do |t, args|
|
29
29
|
db = args.database || [ModelsAuditor.config.connection_namespace, Rails.env].map(&:presence).compact.join('_').to_sym
|
30
30
|
raise ArgumentError.new('Required parameter [<database>] was not passed') if db.blank?
|
31
|
-
database_name = ActiveRecord::Base.configurations[db]['database']
|
31
|
+
database_name = ActiveRecord::Base.configurations[db.to_s]['database']
|
32
32
|
|
33
33
|
puts "Applying create on #{db}"
|
34
34
|
ActiveRecord::Base.connection.create_database(database_name)
|
@@ -38,7 +38,7 @@ namespace :db do
|
|
38
38
|
task :drop, [:database] => [:connect_without_db, :environment] do |t, args|
|
39
39
|
db = args.database || [ModelsAuditor.config.connection_namespace, Rails.env].map(&:presence).compact.join('_').to_sym
|
40
40
|
raise ArgumentError.new('Required parameter [<database>] was not passed') if db.blank?
|
41
|
-
database_name = ActiveRecord::Base.configurations[db]['database']
|
41
|
+
database_name = ActiveRecord::Base.configurations[db.to_s]['database']
|
42
42
|
|
43
43
|
# Дропаем существующие подключения
|
44
44
|
# и запрещаем новые на время пересоздания базы
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: models_auditor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Gorbunov
|
@@ -118,6 +118,7 @@ extensions: []
|
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
120
|
- MIT-LICENSE
|
121
|
+
- README.md
|
121
122
|
- Rakefile
|
122
123
|
- app/assets/javascripts/models_auditor/application.js
|
123
124
|
- app/assets/stylesheets/models_auditor/application.css
|
@@ -185,7 +186,7 @@ files:
|
|
185
186
|
- test/integration/navigation_test.rb
|
186
187
|
- test/models_auditor_test.rb
|
187
188
|
- test/test_helper.rb
|
188
|
-
homepage: https://github.com/
|
189
|
+
homepage: https://github.com/Go-Promo/models_auditor
|
189
190
|
licenses:
|
190
191
|
- MIT
|
191
192
|
metadata: {}
|