attributes_history 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/lib/attributes_history/gem_version.rb +3 -1
- data/lib/attributes_history/has_attributes_history.rb +3 -1
- data/lib/attributes_history/history_retriever.rb +4 -2
- data/lib/attributes_history/history_saver.rb +3 -1
- data/lib/attributes_history/rspec.rb +2 -0
- data/lib/attributes_history.rb +2 -0
- metadata +38 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcb1f022b908387c199bf5bd3e0a6e244fa1cd9086b788027c5499b44a73d6d4
|
4
|
+
data.tar.gz: 27f508b9705d7eab06e1d9f45cf037e4daaf6e700df4eb5d8ed8687052c32e36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec16bb7605efa23209706931059f5caeac3ae0a93619e503fe335b1e1cf7d607b9cbc0e86be4afaa8573365e1872d77482dd80e4aa59cfe7a068b62b0b41eb13
|
7
|
+
data.tar.gz: f776637cf760554a7e75f7c95bb3a602ce1e25bdb3ae3b685b9e9fc1e442471fce2fb6d11c33ced13455b493f18765d1904a0d0abcd599e162cc43313ad4fe91
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support'
|
2
4
|
require_relative 'history_saver'
|
3
5
|
require_relative 'history_retriever'
|
@@ -46,7 +48,7 @@ module AttributesHistory
|
|
46
48
|
def setup_history_callback(history_attributes, history_model)
|
47
49
|
after_update do
|
48
50
|
HistorySaver.new(self, history_attributes, history_model)
|
49
|
-
|
51
|
+
.save_if_needed
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AttributesHistory
|
2
4
|
class HistoryRetriever
|
3
5
|
def initialize(object)
|
@@ -9,7 +11,7 @@ module AttributesHistory
|
|
9
11
|
history_association = @object.class.history_association(attribute)
|
10
12
|
|
11
13
|
history_entry = @cached_history[[history_association, date]] ||=
|
12
|
-
|
14
|
+
find_entry_on(history_association, date)
|
13
15
|
|
14
16
|
history_entry.public_send(attribute)
|
15
17
|
end
|
@@ -18,7 +20,7 @@ module AttributesHistory
|
|
18
20
|
|
19
21
|
def find_entry_on(history_association, date)
|
20
22
|
@object.public_send(history_association)
|
21
|
-
|
23
|
+
.where('recorded_on > ?', date).order(:recorded_on).first || @object
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module AttributesHistory
|
2
4
|
class HistorySaver
|
3
5
|
def initialize(changed_object, history_attributes, history_model)
|
@@ -22,7 +24,7 @@ module AttributesHistory
|
|
22
24
|
@object.class.history_association(@history_attributes.first)
|
23
25
|
|
24
26
|
history_entry = @object.public_send(history_association)
|
25
|
-
|
27
|
+
.find_or_initialize_by(recorded_on: Date.current)
|
26
28
|
|
27
29
|
# If there is an existing history record for today, just leave it as is,
|
28
30
|
# otherwise, save the newly initialized one.
|
data/lib/attributes_history.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attributes_history
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- draffensperger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '3.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '8.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '3.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '8.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '3.0'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '8.0'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,91 +49,91 @@ dependencies:
|
|
49
49
|
version: '3.0'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '8.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: pry
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- - "
|
57
|
+
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: '0'
|
60
60
|
type: :development
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- - "
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
66
|
+
version: '0'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
68
|
+
name: pry-byebug
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
73
|
+
version: '0'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: '0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: rails
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0
|
87
|
+
version: '7.0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: 0
|
94
|
+
version: '7.0'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
|
-
name:
|
96
|
+
name: rspec-rails
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
|
-
- - "
|
99
|
+
- - "~>"
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: 3.8.0
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- - "
|
106
|
+
- - "~>"
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
108
|
+
version: 3.8.0
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
|
-
name:
|
110
|
+
name: rubocop
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
|
-
- - "
|
113
|
+
- - "~>"
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
115
|
+
version: 0.61.0
|
116
116
|
type: :development
|
117
117
|
prerelease: false
|
118
118
|
version_requirements: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- - "
|
120
|
+
- - "~>"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
122
|
+
version: 0.61.0
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
|
-
name:
|
124
|
+
name: sqlite3
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
|
-
- - "
|
127
|
+
- - "~>"
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
129
|
+
version: '1.7'
|
130
130
|
type: :development
|
131
131
|
prerelease: false
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
133
133
|
requirements:
|
134
|
-
- - "
|
134
|
+
- - "~>"
|
135
135
|
- !ruby/object:Gem::Version
|
136
|
-
version: '
|
136
|
+
version: '1.7'
|
137
137
|
description: Date-granular history for specified model fields. Compact & easy to query.
|
138
138
|
email:
|
139
139
|
- d.raffensperger@gmail.com
|
@@ -154,7 +154,7 @@ homepage: https://github.com/CruGlobal/attributes_history
|
|
154
154
|
licenses:
|
155
155
|
- MIT
|
156
156
|
metadata: {}
|
157
|
-
post_install_message:
|
157
|
+
post_install_message:
|
158
158
|
rdoc_options: []
|
159
159
|
require_paths:
|
160
160
|
- lib
|
@@ -169,9 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
|
-
|
173
|
-
|
174
|
-
signing_key:
|
172
|
+
rubygems_version: 3.5.9
|
173
|
+
signing_key:
|
175
174
|
specification_version: 4
|
176
175
|
summary: Date-granular history for specified model fields. Compact & easy to query.
|
177
176
|
test_files: []
|