recorder 0.1.0 → 0.1.1

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: 2b3955ec8b5c54010caff1d1e24aa92bcb2c5b43
4
- data.tar.gz: ded550166b4025bc612fe913d4e79a480f2d06f4
3
+ metadata.gz: 04b0b14fc30386cd30b206daa0cb70ca0c6e41c3
4
+ data.tar.gz: edaec63b8d20474305a7bc0c5ab5a8af1bcfd674
5
5
  SHA512:
6
- metadata.gz: 3b77a10f6e0ded0fc17d52ac885b9a89a7cb70b6052d616f45c33a189e15d3f3aba2c6db97b4fac9689daf121d020f65ab4afa61bf9b291c601de5c61928be94
7
- data.tar.gz: 3b1ff7aa9ee10e24babbe23ae278c4047e64c26e4ee45f5128107872f05d30f7679d800a019656c9172567f34e5f4be16e1319ed0a512a2e5f7bb334183537b8
6
+ metadata.gz: b44c6ae6cd9601f2d8bb7705c9a3e6c01090c574c8bf3f139b72aee8d55e2e12a5553c3824f461a22bbc9d729a7aba1cd0bebfc13ab148a4700b43fc69811e60
7
+ data.tar.gz: 0e1416888ae65f8fadb465577612ba79a90bd603df248091b420afe0d079147913a05967185faf9e5d4decc9988093783d82d5c503abafcda15737440cf66290
@@ -0,0 +1,29 @@
1
+ class Recorder::Changeset
2
+ attr_reader :item, :changes
3
+
4
+ def initialize(item, changes)
5
+ @item = item; @changes = changes
6
+ end
7
+
8
+ def attributes
9
+ self.changes.keys
10
+ end
11
+
12
+ def human_attribute_name(attribute)
13
+ self.item.class.human_attribute_name(attribute.to_s)
14
+ end
15
+
16
+ def before(attribute)
17
+ self.changes[attribute.to_s][0]
18
+ end
19
+
20
+ def after(attribute)
21
+ self.changes[attribute.to_s][1]
22
+ end
23
+
24
+ # def
25
+
26
+ # def item_human_attribute_name(attribute)
27
+ # self.item.source.class.human_attribute_name(attribute)
28
+ # end
29
+ end
@@ -5,8 +5,19 @@ module Recorder
5
5
  base.decorates_association :item
6
6
  end
7
7
 
8
- def item_human_attribute_name(attribute)
9
- self.item.source.class.human_attribute_name(attribute)
8
+ def item_changeset
9
+ @item_changeset ||= Recorder::Changeset.new(self.item.source, source.data['changes'])
10
+ end
11
+
12
+ def changed_associations
13
+ source.data['associations'].keys#.map{ |association| self.item_human_attribute_name(association) }
14
+ end
15
+
16
+ def association_changeset(name)
17
+ association = self.item.send(name)
18
+ association = association.source if association.decorated?
19
+
20
+ Recorder::Changeset.new(association, source.data['associations'].fetch(name.to_s).try(:fetch, 'changes'))
10
21
  end
11
22
  end
12
23
  end
@@ -3,7 +3,7 @@ module Recorder
3
3
  module VERSION
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 0
6
+ TINY = 1
7
7
  PRE = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
data/lib/recorder.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'recorder/changeset'
1
2
  require 'recorder/version'
2
3
  require 'recorder/observer'
3
4
  require 'recorder/rails/controller_concern'
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Alexandrov
@@ -140,6 +140,7 @@ files:
140
140
  - lib/generators/recorder/install_generator.rb
141
141
  - lib/generators/recorder/templates/create_recorder_revisions.rb
142
142
  - lib/recorder.rb
143
+ - lib/recorder/changeset.rb
143
144
  - lib/recorder/draper/decorator_concern.rb
144
145
  - lib/recorder/observer.rb
145
146
  - lib/recorder/rails/controller_concern.rb