historyable 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -3
- data/lib/historyable.rb +14 -15
- data/lib/historyable/version.rb +1 -1
- metadata +7 -63
- metadata.gz.sig +1 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzU1M2JlMTY5YjkyMjUyMmI1NTVmZDgwNTA1NDY5MmViYTQ2YjJiOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGEyNzQyY2JlMWMyMzU3NTI0NGJkNTVhMTNiNmU2MzAxYzA2M2IxMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjU4NmFmMGVjODIyYWI1YTNjYTRiZDA4OWI0NDBhZTkzNjFjZTNlMWVmOTM5
|
10
|
+
ZjY5MTY0Zjc3M2U3MDdjMjg3OGRhYmMzZjNmY2VjMzdiODllY2IzMzcwYzI2
|
11
|
+
N2E3NWE3ZTM2NjQ3OGQ4OTJiMWEwZDljZDRlMDViMWM1ZTkwYTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzUyZjJmNmYwMGI4NmVhZmVmMGEzODVmYTNlZTM5N2JkYjE5ZDM4Y2JjMTUx
|
14
|
+
YTU5MGIxYjgxZmQ5ZmM0OTc3ZTZkNTY3YjQzZDkzOGJhOWFlNWE0OGUwYWEy
|
15
|
+
NGQyZGUyMmMxYTkwNmNlNGQzODI4NDg2YmQ2M2Q1YzRiMjNlMDA=
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
ƙ
|
1
|
+
a�~�rk`��C�W�;�}{��N�w����3*f�Dz��*��7��ZH�m_7{wn,�t�#ut��zӬ��X�dq��y�J������g��h��U��������µ4"wL�3��t�ƿ���jq�߸+��6��A�������ѻ����ZΜ����J
|
2
|
+
;�
|
data/lib/historyable.rb
CHANGED
@@ -4,24 +4,28 @@ require 'active_record'
|
|
4
4
|
require 'historyable/change'
|
5
5
|
|
6
6
|
module Historyable
|
7
|
-
Item = Struct.new(:attribute_name, :association_name)
|
8
|
-
|
9
7
|
extend ActiveSupport::Concern
|
10
8
|
|
9
|
+
Item = Struct.new(:attribute_name, :association_name)
|
10
|
+
|
11
11
|
included do
|
12
|
-
class_attribute :historyable_items, instance_writer: false
|
12
|
+
class_attribute :historyable_items, :historyable_cache, instance_writer: false
|
13
13
|
end
|
14
14
|
|
15
15
|
|
16
16
|
module ClassMethods
|
17
17
|
|
18
|
+
# Define
|
19
|
+
#
|
20
|
+
#
|
18
21
|
# @param attributes [Array, Symbol]
|
19
22
|
def has_history(*attributes)
|
23
|
+
self.historyable_cache = ActiveSupport::Cache::MemoryStore.new
|
20
24
|
self.historyable_items = attributes.map do |attribute|
|
21
25
|
attribute_name = attribute.to_sym
|
22
26
|
association_name = attribute.to_s.insert(-1, '_changes').to_sym
|
23
27
|
|
24
|
-
|
28
|
+
Item.new(attribute_name, association_name)
|
25
29
|
end
|
26
30
|
|
27
31
|
# Associations
|
@@ -58,7 +62,7 @@ module Historyable
|
|
58
62
|
send(historyable.association_name)
|
59
63
|
.where(object_attribute: historyable.attribute_name)
|
60
64
|
.order('created_at DESC')
|
61
|
-
.select(:object_attribute_value, :created_at)
|
65
|
+
.select([:object_attribute_value, :created_at])
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
@@ -71,24 +75,19 @@ module Historyable
|
|
71
75
|
# @return [Array]
|
72
76
|
def define_historyable_attribute_history(historyable)
|
73
77
|
define_method("#{historyable.attribute_name.to_s}_history") do
|
74
|
-
|
78
|
+
historyable_cache.fetch(historyable.attribute_name) do
|
75
79
|
collection = []
|
76
80
|
|
77
81
|
records = send("#{historyable.attribute_name}_history_raw")
|
78
|
-
|
79
|
-
records.map do |attribute_value, created_at|
|
82
|
+
records.each do |record|
|
80
83
|
item = HashWithIndifferentAccess.new
|
81
|
-
item[:attribute_value] =
|
82
|
-
item[:changed_at] = created_at
|
84
|
+
item[:attribute_value] = record.object_attribute_value
|
85
|
+
item[:changed_at] = record.created_at
|
83
86
|
|
84
87
|
collection << item
|
85
88
|
end
|
86
89
|
|
87
|
-
# Sets attribute_history cache
|
88
|
-
instance_variable_set("@#{historyable.attribute_name.to_s}_history".to_sym, collection)
|
89
90
|
collection
|
90
|
-
else
|
91
|
-
instance_variable_get("@#{historyable.attribute_name.to_s}_history".to_sym)
|
92
91
|
end
|
93
92
|
end
|
94
93
|
end
|
@@ -122,7 +121,7 @@ module Historyable
|
|
122
121
|
send(historyable.association_name).create(object_attribute: historyable.attribute_name,
|
123
122
|
object_attribute_value: send(historyable.attribute_name))
|
124
123
|
# Expires attribute_history cache
|
125
|
-
|
124
|
+
historyable_cache.delete(historyable.attribute_name)
|
126
125
|
end
|
127
126
|
|
128
127
|
true
|
data/lib/historyable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: historyable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philippe Dionne
|
@@ -45,85 +45,29 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - ! '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 3.
|
48
|
+
version: 3.2.14
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 3.
|
53
|
+
version: 3.2.14
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
name: activerecord
|
57
|
-
- !ruby/object:Gem::Dependency
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '1.3'
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ~>
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '1.3'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
name: bundler
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ! '>='
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ! '>='
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
name: rake
|
85
57
|
- !ruby/object:Gem::Dependency
|
86
58
|
requirement: !ruby/object:Gem::Requirement
|
87
59
|
requirements:
|
88
60
|
- - ! '>='
|
89
61
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
62
|
+
version: 3.2.14
|
91
63
|
version_requirements: !ruby/object:Gem::Requirement
|
92
64
|
requirements:
|
93
65
|
- - ! '>='
|
94
66
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
96
|
-
type: :
|
97
|
-
prerelease: false
|
98
|
-
name: rspec
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - ! '>='
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '0'
|
105
|
-
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
name: sqlite3
|
113
|
-
- !ruby/object:Gem::Dependency
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - ! '>='
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '0'
|
119
|
-
version_requirements: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - ! '>='
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '0'
|
124
|
-
type: :development
|
67
|
+
version: 3.2.14
|
68
|
+
type: :runtime
|
125
69
|
prerelease: false
|
126
|
-
name:
|
70
|
+
name: activesupport
|
127
71
|
description: A simple and solid concern to track ActiveRecord models attributes changes.
|
128
72
|
email:
|
129
73
|
- philippe.dionne@hooktstudios.com
|
metadata.gz.sig
CHANGED