recorder 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/recorder/changeset.rb +1 -1
- data/lib/recorder/revision.rb +19 -3
- data/lib/recorder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc488336fc2f5088c56568c815dbd167ff017c56
|
4
|
+
data.tar.gz: 25d597df1d310b86477758f3b852f87af4f8edbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdd3bcfa8e51c4832660a87dee1ba8c0fceff24818a914e38d510291eee68ea3e24925ab53b379af34f563bfb008e96af66bd276232cb40b7dfef3cf85d7f917
|
7
|
+
data.tar.gz: 0075a5c6b3f48838928050dc034d506673a29213b4f3a9b80e7bde7911beb3347f64fb2a96a0e9584daffba209c4fcc06c177a426189156e771dfeb6f69ff8a4
|
data/lib/recorder/changeset.rb
CHANGED
data/lib/recorder/revision.rb
CHANGED
@@ -25,28 +25,44 @@ class Recorder::Revision < ActiveRecord::Base
|
|
25
25
|
|
26
26
|
scope :ordered_by_created_at, -> { order(:created_at => :desc) }
|
27
27
|
|
28
|
+
# Get changeset for an item
|
29
|
+
# @return [Recorder::Changeset]
|
28
30
|
def item_changeset
|
29
31
|
return @item_changeset if defined?(@item_changeset)
|
30
32
|
|
31
|
-
@item_changeset ||= self.
|
33
|
+
@item_changeset ||= self.changeset_class(self.item).new(self.item, self.data['changes'])
|
32
34
|
end
|
33
35
|
|
36
|
+
# Get names of item associations that has been changed
|
37
|
+
# @return [Array]
|
34
38
|
def changed_associations
|
35
39
|
self.data['associations'].try(:keys) || []
|
36
40
|
end
|
37
41
|
|
42
|
+
# Get changeset for an association
|
43
|
+
# @param name [String] name of association to return changeset
|
44
|
+
# @return [Recorder::Changeset]
|
38
45
|
def association_changeset(name)
|
39
46
|
association = self.item.send(name)
|
40
47
|
# association = association.source if association.decorated?
|
41
48
|
|
42
|
-
self.
|
49
|
+
self.changeset_class(association).new(association, self.data['associations'].fetch(name.to_s).try(:fetch, 'changes'))
|
43
50
|
end
|
44
51
|
|
45
52
|
protected
|
46
53
|
|
47
|
-
|
54
|
+
# Returns changeset class for passed object.
|
55
|
+
# Changeset class name can be overriden with `#recorder_changeset_class` method.
|
56
|
+
# If `#recorder_changeset_class` method is not defined, then class name is generated as "#{class}Changeset"
|
57
|
+
# @api private
|
58
|
+
def changeset_class(object)
|
48
59
|
klass = (defined?(Draper) && object.decorated?) ? object.source.class : object.class
|
49
60
|
klass = klass.base_class
|
61
|
+
|
62
|
+
if klass.respond_to?(:recorder_changeset_class)
|
63
|
+
return klass.send(:recorder_changeset_class)
|
64
|
+
end
|
65
|
+
|
50
66
|
klass = "#{klass}Changeset"
|
51
67
|
|
52
68
|
klass = klass.constantize rescue nil
|
data/lib/recorder/version.rb
CHANGED