recorder 0.1.9 → 0.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c182309616587aca8b7687b1b2db50f7db652df0
4
- data.tar.gz: 49c4a22471ede9c20df843718757d6311406e9c6
3
+ metadata.gz: bc488336fc2f5088c56568c815dbd167ff017c56
4
+ data.tar.gz: 25d597df1d310b86477758f3b852f87af4f8edbc
5
5
  SHA512:
6
- metadata.gz: cfeaeac2ef036d3634a0e6394ac7cbc99fc2e27c8ccbec79616bb82bcd490b31510a5d2957f840511daa4ebf43923b18eaff9e562551aeedaf86fdd7d055782c
7
- data.tar.gz: 43f18df08aa61b29c1d93dc57400a241fa8619714c8a541daa0e2d76ccd78c32a9b85450a1c56ea0732f1dc5a0801b69f6be2568599be59989242e45a8c7e70d
6
+ metadata.gz: cdd3bcfa8e51c4832660a87dee1ba8c0fceff24818a914e38d510291eee68ea3e24925ab53b379af34f563bfb008e96af66bd276232cb40b7dfef3cf85d7f917
7
+ data.tar.gz: 0075a5c6b3f48838928050dc034d506673a29213b4f3a9b80e7bde7911beb3347f64fb2a96a0e9584daffba209c4fcc06c177a426189156e771dfeb6f69ff8a4
@@ -7,7 +7,7 @@ module Recorder
7
7
  end
8
8
 
9
9
  def keys
10
- self.changes.keys
10
+ self.changes.try(:keys) || []
11
11
  end
12
12
 
13
13
  def human_attribute_name(attribute)
@@ -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.changeset_klass(self.item).new(self.item, self.data['changes'])
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.changeset_klass(association).new(association, self.data['associations'].fetch(name.to_s).try(:fetch, 'changes'))
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
- def changeset_klass(object)
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
@@ -3,7 +3,7 @@ module Recorder
3
3
  module VERSION
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 9
6
+ TINY = 10
7
7
  PRE = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Alexandrov