logidze 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +8 -0
- data/README.md +13 -13
- data/Rakefile +1 -1
- data/lib/logidze/has_logidze.rb +1 -1
- data/lib/logidze/model.rb +19 -14
- data/lib/logidze/version.rb +1 -1
- data/logidze.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954f27b8037b7a3a1f73ab87ef9358ede18b273c
|
4
|
+
data.tar.gz: 66f9848eda590c426b3bb7694cadf2bc6224fba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdca34e05f8021233e5b1663ccc773553725b6108728e1f407545dab153e917d0dc12c6ffebccc5a802fe576f51cedd653a89c93b281d7132682590bac5e1687
|
7
|
+
data.tar.gz: 024a6a76b6ea16bad9218a0a07b3c275dc629e353abf325630b9036c306e5a1da30d975ed1ae98d0f6dd164b980fc18d87397872f2f8e3e25daddedb1813db64
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-md
|
3
|
+
|
1
4
|
AllCops:
|
2
5
|
# Include gemspec and Rakefile
|
3
6
|
Include:
|
@@ -7,6 +10,8 @@ AllCops:
|
|
7
10
|
Exclude:
|
8
11
|
- 'bin/**/*'
|
9
12
|
- 'spec/dummy/**/*'
|
13
|
+
- 'vendor/**/*'
|
14
|
+
- 'gemfiles/**/*'
|
10
15
|
- 'tmp/**/*'
|
11
16
|
- 'bench/**/*'
|
12
17
|
- 'Rakefile'
|
@@ -45,6 +50,10 @@ Lint/AmbiguousRegexpLiteral:
|
|
45
50
|
Lint/MissingCopEnableDirective:
|
46
51
|
Enabled: false
|
47
52
|
|
53
|
+
Lint/UselessAssignment:
|
54
|
+
Exclude:
|
55
|
+
- '**/*.md'
|
56
|
+
|
48
57
|
Metrics/MethodLength:
|
49
58
|
Exclude:
|
50
59
|
- 'spec/**/*.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## master
|
4
|
+
|
5
|
+
## 0.6.3 (2018-01-17)
|
6
|
+
|
7
|
+
- [Fixes [#57](https://github.com/palkan/logidze/issues/57)] Support associations versioning for `at(version:)`. ([@palkan][])
|
8
|
+
|
9
|
+
- Add [`rubocop-md`](https://github.com/palkan/rubocop-md)
|
10
|
+
|
3
11
|
## 0.6.2 (2018-01-11)
|
4
12
|
|
5
13
|
- [Fixes [#53](https://github.com/palkan/logidze/issues/53)] Fix storing empty log entries with blacklisting. ([@charlie-wasp][])
|
data/README.md
CHANGED
@@ -20,15 +20,15 @@ Other requirements:
|
|
20
20
|
|
21
21
|
## Installation
|
22
22
|
|
23
|
-
|
23
|
+
Add Logidze to your application's Gemfile:
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
gem 'logidze'
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
Install required DB extensions and create trigger function:
|
30
30
|
|
31
|
-
```
|
31
|
+
```sh
|
32
32
|
rails generate logidze:install
|
33
33
|
```
|
34
34
|
|
@@ -36,13 +36,13 @@ This creates migration for adding trigger function and enabling hstore extension
|
|
36
36
|
|
37
37
|
Run migrations:
|
38
38
|
|
39
|
-
```
|
39
|
+
```sh
|
40
40
|
rake db:migrate
|
41
41
|
```
|
42
42
|
|
43
43
|
3. Add log column and triggers to the model:
|
44
44
|
|
45
|
-
```
|
45
|
+
```sh
|
46
46
|
rails generate logidze:model Post
|
47
47
|
rake db:migrate
|
48
48
|
```
|
@@ -51,19 +51,19 @@ This also adds `has_logidze` line to your model, which adds methods for working
|
|
51
51
|
|
52
52
|
You can provide `limit` option to `generate` to limit the size of the log (by default it's unlimited):
|
53
53
|
|
54
|
-
```
|
54
|
+
```sh
|
55
55
|
rails generate logidze:model Post --limit=10
|
56
56
|
```
|
57
57
|
|
58
58
|
To backfill table data (i.e. create initial snapshots) add `backfill` option:
|
59
59
|
|
60
|
-
```
|
60
|
+
```sh
|
61
61
|
rails generate logidze:model Post --backfill
|
62
62
|
```
|
63
63
|
|
64
64
|
You can log only particular columns changes. There are mutually exclusive `blacklist` and `whitelist` options for this:
|
65
65
|
|
66
|
-
```
|
66
|
+
```sh
|
67
67
|
# track all columns, except `created_at` and `active`
|
68
68
|
rails generate logidze:model Post --blacklist=created_at active
|
69
69
|
# track only `title` and `body` columns
|
@@ -72,7 +72,7 @@ rails generate logidze:model Post --whitelist=title body
|
|
72
72
|
|
73
73
|
By default, Logidze tries to infer the path to the model file from the model name and may fail, for example, if you have unconventional project structure. In that case you should specify the path explicitly:
|
74
74
|
|
75
|
-
```
|
75
|
+
```sh
|
76
76
|
rails generate logidze:model Post --path "app/models/custom/post.rb"
|
77
77
|
```
|
78
78
|
|
@@ -80,7 +80,7 @@ By default, Logidze tries to get a timestamp for a version from record's `update
|
|
80
80
|
your model does not have that column, Logidze will gracefully fall back to `statement_timestamp()`.
|
81
81
|
To change the column name or disable this feature completely, you can use the `timestamp_column` option:
|
82
82
|
|
83
|
-
```
|
83
|
+
```sh
|
84
84
|
# will try to get the timestamp value from `time` column
|
85
85
|
rails generate logidze:model Post --timestamp_column time
|
86
86
|
# will always set version timestamp to `statement_timestamp()`
|
@@ -89,7 +89,7 @@ rails generate logidze:model Post --timestamp_column nil # "null" and "false" wi
|
|
89
89
|
|
90
90
|
If you want to update Logidze settings for the model, run migration with `--update` flag:
|
91
91
|
|
92
|
-
```
|
92
|
+
```sh
|
93
93
|
rails generate logidze:model Post --update --whitelist=title body rating
|
94
94
|
```
|
95
95
|
|
@@ -112,7 +112,7 @@ Nevertheless, you still need super-user privileges to enable `hstore` extension
|
|
112
112
|
|
113
113
|
We try to make upgrade process as simple as possible. For now, the only required action is to create and run a migration:
|
114
114
|
|
115
|
-
```
|
115
|
+
```sh
|
116
116
|
rails generate logidze:install --update
|
117
117
|
```
|
118
118
|
|
@@ -232,7 +232,7 @@ And in your controller:
|
|
232
232
|
|
233
233
|
```ruby
|
234
234
|
class ApplicationController < ActionController::Base
|
235
|
-
around_action :set_logidze_responsible, only: [
|
235
|
+
around_action :set_logidze_responsible, only: %i[create update]
|
236
236
|
|
237
237
|
def set_logidze_responsible(&block)
|
238
238
|
Logidze.with_responsible(current_user&.id, &block)
|
data/Rakefile
CHANGED
data/lib/logidze/has_logidze.rb
CHANGED
data/lib/logidze/model.rb
CHANGED
@@ -63,7 +63,7 @@ module Logidze
|
|
63
63
|
# Return a dirty copy of record at specified time
|
64
64
|
# If time/version is less then the first version, then return nil.
|
65
65
|
# If time/version is greater then the last version, then return self.
|
66
|
-
# rubocop: disable Metrics/
|
66
|
+
# rubocop: disable Metrics/MethodLength
|
67
67
|
def at(ts = nil, time: nil, version: nil)
|
68
68
|
Deprecations.show_ts_deprecation_for("#at") if ts
|
69
69
|
|
@@ -79,16 +79,11 @@ module Logidze
|
|
79
79
|
return self
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
object_at = dup
|
85
|
-
object_at.apply_diff(version, log_data.changes_to(version: version))
|
86
|
-
object_at.id = id
|
87
|
-
object_at.logidze_requested_ts = time
|
82
|
+
log_entry = log_data.find_by_time(time)
|
88
83
|
|
89
|
-
|
84
|
+
build_dup(log_entry, time)
|
90
85
|
end
|
91
|
-
# rubocop: enable Metrics/
|
86
|
+
# rubocop: enable Metrics/MethodLength
|
92
87
|
|
93
88
|
# Revert record to the version at specified time (without saving to DB)
|
94
89
|
def at!(ts = nil, time: nil, version: nil)
|
@@ -110,10 +105,11 @@ module Logidze
|
|
110
105
|
# Return a dirty copy of specified version of record
|
111
106
|
def at_version(version)
|
112
107
|
return self if log_data.version == version
|
113
|
-
return nil unless log_data.find_by_version(version)
|
114
108
|
|
115
|
-
|
116
|
-
|
109
|
+
log_entry = log_data.find_by_version(version)
|
110
|
+
return nil unless log_entry
|
111
|
+
|
112
|
+
build_dup(log_entry)
|
117
113
|
end
|
118
114
|
|
119
115
|
# Revert record to the specified version (without saving to DB)
|
@@ -176,12 +172,12 @@ module Logidze
|
|
176
172
|
|
177
173
|
return association unless Logidze.associations_versioning
|
178
174
|
|
179
|
-
|
175
|
+
should_apply_logidze =
|
180
176
|
logidze_past? &&
|
181
177
|
association.klass.respond_to?(:has_logidze?) &&
|
182
178
|
!association.singleton_class.include?(Logidze::VersionedAssociation)
|
183
179
|
|
184
|
-
return association unless
|
180
|
+
return association unless should_apply_logidze
|
185
181
|
|
186
182
|
association.singleton_class.prepend Logidze::VersionedAssociation
|
187
183
|
|
@@ -210,6 +206,15 @@ module Logidze
|
|
210
206
|
write_attribute column, deserialize_value(column, value)
|
211
207
|
end
|
212
208
|
|
209
|
+
def build_dup(log_entry, requested_ts = log_entry.time)
|
210
|
+
object_at = dup
|
211
|
+
object_at.apply_diff(log_entry.version, log_data.changes_to(version: log_entry.version))
|
212
|
+
object_at.id = id
|
213
|
+
object_at.logidze_requested_ts = requested_ts
|
214
|
+
|
215
|
+
object_at
|
216
|
+
end
|
217
|
+
|
213
218
|
if Rails::VERSION::MAJOR < 5
|
214
219
|
def deserialize_value(column, value)
|
215
220
|
@attributes[column].type.type_cast_from_database(value)
|
data/lib/logidze/version.rb
CHANGED
data/logidze.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rake", ">= 10.0"
|
28
28
|
spec.add_development_dependency "rspec-rails", ">= 3.4"
|
29
29
|
spec.add_development_dependency "rubocop", "~> 0.52"
|
30
|
+
spec.add_development_dependency "rubocop-md", "~> 0.2.0"
|
30
31
|
spec.add_development_dependency "simplecov", ">= 0.3.8"
|
31
32
|
spec.add_development_dependency "timecop", "~> 0.8"
|
32
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logidze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0.52'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-md
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.2.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.2.0
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: simplecov
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|