recorder 0.1.2 → 0.1.3
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/lib/recorder/changeset.rb +37 -9
- data/lib/recorder/draper/decorator_concern.rb +17 -4
- data/lib/recorder/observer.rb +8 -4
- data/lib/recorder/tape.rb +6 -8
- data/lib/recorder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e7c1bf50c6c1844ee0961756ffe1ab06128991
|
4
|
+
data.tar.gz: 51d81209e457c6d099f3ffb168ac261bcf559aed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0d3fc8fb50bbb4bb2d87ad02cb2086669e6cced785e65a96a4f911a1ec6e33d0a4dcf81feecdc8bf6299e9fefe8601ae5fd54845f9ce0c8a100f256b26d278b
|
7
|
+
data.tar.gz: 4812c0ac7f9c24fb614f7eb9f038c42ab57b5a732e319674d89ad87fe374fb4dd513077a881330e3a496859a7f3d1677ee1108c0818c3c3829d064a051d734d1
|
data/lib/recorder/changeset.rb
CHANGED
@@ -6,24 +6,52 @@ module Recorder
|
|
6
6
|
@item = item; @changes = changes
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def keys
|
10
10
|
self.changes.keys
|
11
11
|
end
|
12
12
|
|
13
13
|
def human_attribute_name(attribute)
|
14
|
-
self.item.
|
14
|
+
if defined?(Draper) && self.item.decorated?
|
15
|
+
self.item.source.class.human_attribute_name(attribute.to_s)
|
16
|
+
else
|
17
|
+
self.item.class.human_attribute_name(attribute.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def previous(attribute)
|
23
|
+
# self.changes[attribute.to_s][0]
|
24
|
+
# self.previous_version.try("display_#{attribute}") || self.previous_version.try(attribute)
|
25
|
+
self.try("previous_#{attribute}") || self.previous_version.try(attribute)
|
15
26
|
end
|
16
27
|
|
17
|
-
def
|
18
|
-
|
28
|
+
def previous_version
|
29
|
+
return @previous_version if defined?(@previous_version)
|
30
|
+
|
31
|
+
@previous_version = self.item.dup
|
32
|
+
|
33
|
+
self.changes.each do |key, change|
|
34
|
+
@previous_version.send("#{key}=", change[0])
|
35
|
+
end
|
36
|
+
|
37
|
+
@previous_version
|
19
38
|
end
|
20
39
|
|
21
|
-
def
|
22
|
-
self.
|
40
|
+
def next(attribute)
|
41
|
+
self.try("next_#{attribute}") || self.next_version.send(attribute)
|
42
|
+
# self.next_version.try("display_#{attribute}") || self.next_version.try(attribute)
|
23
43
|
end
|
24
44
|
|
25
|
-
|
26
|
-
|
27
|
-
|
45
|
+
def next_version
|
46
|
+
return @next_version if defined?(@next_version)
|
47
|
+
|
48
|
+
@next_version = self.item.dup
|
49
|
+
|
50
|
+
self.changes.each do |key, change|
|
51
|
+
@next_version.send("#{key}=", change[1])
|
52
|
+
end
|
53
|
+
|
54
|
+
@next_version
|
55
|
+
end
|
28
56
|
end
|
29
57
|
end
|
@@ -6,18 +6,31 @@ module Recorder
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def item_changeset
|
9
|
-
@item_changeset
|
9
|
+
return @item_changeset if defined?(@item_changeset)
|
10
|
+
|
11
|
+
@item_changeset ||= self.changeset_klass(self.item.source).new(self.item, source.data['changes'])
|
10
12
|
end
|
11
13
|
|
12
14
|
def changed_associations
|
13
|
-
source.data['associations'].keys
|
15
|
+
source.data['associations'].keys
|
14
16
|
end
|
15
17
|
|
16
18
|
def association_changeset(name)
|
17
19
|
association = self.item.send(name)
|
18
|
-
association = association.source if association.decorated?
|
20
|
+
# association = association.source if association.decorated?
|
21
|
+
|
22
|
+
self.changeset_klass(association).new(association, source.data['associations'].fetch(name.to_s).try(:fetch, 'changes'))
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def changeset_klass(object)
|
28
|
+
klass = object.decorated? ? object.source.class : object.class
|
29
|
+
klass = klass.base_class
|
30
|
+
klass = "#{klass}Changeset"
|
19
31
|
|
20
|
-
|
32
|
+
klass = klass.constantize rescue nil
|
33
|
+
klass.present? ? klass : Recorder::Changeset
|
21
34
|
end
|
22
35
|
end
|
23
36
|
end
|
data/lib/recorder/observer.rb
CHANGED
@@ -10,17 +10,21 @@ module Recorder
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module ClassMethods
|
13
|
-
def
|
13
|
+
def recorder(options = {})
|
14
|
+
define_method 'recorder_option' do
|
15
|
+
options
|
16
|
+
end
|
17
|
+
|
14
18
|
after_commit :on => :create do
|
15
|
-
Recorder::Tape.new(self
|
19
|
+
Recorder::Tape.new(self).record_create
|
16
20
|
end
|
17
21
|
|
18
22
|
after_commit :on => :update do
|
19
|
-
Recorder::Tape.new(self
|
23
|
+
Recorder::Tape.new(self).record_update
|
20
24
|
end
|
21
25
|
|
22
26
|
after_commit :on => :destroy do
|
23
|
-
Recorder::Tape.new(self
|
27
|
+
Recorder::Tape.new(self).record_destroy
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
data/lib/recorder/tape.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module Recorder
|
2
2
|
class Tape
|
3
|
-
attr_reader :item
|
3
|
+
attr_reader :item
|
4
4
|
|
5
|
-
def initialize(item
|
6
|
-
@item = item
|
7
|
-
@options = options
|
5
|
+
def initialize(item)
|
6
|
+
@item = item;
|
8
7
|
end
|
9
8
|
|
10
9
|
def record_create
|
@@ -56,13 +55,12 @@ module Recorder
|
|
56
55
|
end
|
57
56
|
|
58
57
|
def sanitize_attributes(attributes = {})
|
59
|
-
|
60
|
-
attributes.symbolize_keys.except(:created_at, :updated_at, :delta)
|
58
|
+
attributes.symbolize_keys.except(self.item.recorder_options[:except])
|
61
59
|
end
|
62
60
|
|
63
61
|
def parse_associations_attributes
|
64
|
-
if self.
|
65
|
-
self.
|
62
|
+
if self.item.recorder_options[:associations].any?
|
63
|
+
self.item.recorder_options[:associations].inject({}) do |hash, association|
|
66
64
|
reflection = self.item.class.reflect_on_association(association)
|
67
65
|
if reflection.present?
|
68
66
|
if reflection.collection?
|
data/lib/recorder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recorder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|