recorder 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04b0b14fc30386cd30b206daa0cb70ca0c6e41c3
4
- data.tar.gz: edaec63b8d20474305a7bc0c5ab5a8af1bcfd674
3
+ metadata.gz: f0c80f7cee2e38cf2926994bf24de8efd4db6cb5
4
+ data.tar.gz: 57bf290b34bb02949f2ddfcd4bc560a9b4aa0d20
5
5
  SHA512:
6
- metadata.gz: b44c6ae6cd9601f2d8bb7705c9a3e6c01090c574c8bf3f139b72aee8d55e2e12a5553c3824f461a22bbc9d729a7aba1cd0bebfc13ab148a4700b43fc69811e60
7
- data.tar.gz: 0e1416888ae65f8fadb465577612ba79a90bd603df248091b420afe0d079147913a05967185faf9e5d4decc9988093783d82d5c503abafcda15737440cf66290
6
+ metadata.gz: d25f3f23d9b3527a3e3a1fee809beb21bb5988079b9798221cd1607e04283445cdb13bd89cdb519e0e21687ca75eee2c6f6790bffbc5e8d180899e01b6fd24c6
7
+ data.tar.gz: e733f79ed49cb43195eab6b06e53789a7f577bddd3bc1e7550533b058f4233b861743c64481e11e4d801e5446ef9592fe608599f1bf364f0752e52302ff88b4f
@@ -1,29 +1,29 @@
1
- class Recorder::Changeset
2
- attr_reader :item, :changes
1
+ module Recorder
2
+ class Changeset
3
+ attr_reader :item, :changes
3
4
 
4
- def initialize(item, changes)
5
- @item = item; @changes = changes
6
- end
5
+ def initialize(item, changes)
6
+ @item = item; @changes = changes
7
+ end
7
8
 
8
- def attributes
9
- self.changes.keys
10
- end
9
+ def attributes
10
+ self.changes.keys
11
+ end
11
12
 
12
- def human_attribute_name(attribute)
13
- self.item.class.human_attribute_name(attribute.to_s)
14
- end
13
+ def human_attribute_name(attribute)
14
+ self.item.class.human_attribute_name(attribute.to_s)
15
+ end
15
16
 
16
- def before(attribute)
17
- self.changes[attribute.to_s][0]
18
- end
17
+ def before(attribute)
18
+ self.changes[attribute.to_s][0]
19
+ end
19
20
 
20
- def after(attribute)
21
- self.changes[attribute.to_s][1]
22
- end
23
-
24
- # def
21
+ def after(attribute)
22
+ self.changes[attribute.to_s][1]
23
+ end
25
24
 
26
- # def item_human_attribute_name(attribute)
27
- # self.item.source.class.human_attribute_name(attribute)
28
- # end
25
+ # def item_human_attribute_name(attribute)
26
+ # self.item.source.class.human_attribute_name(attribute)
27
+ # end
28
+ end
29
29
  end
@@ -1,25 +1,27 @@
1
1
  require 'recorder/tape'
2
2
  require 'active_support/concern'
3
3
 
4
- module Recorder::Observer
5
- extend ::ActiveSupport::Concern
4
+ module Recorder
5
+ module Observer
6
+ extend ::ActiveSupport::Concern
6
7
 
7
- included do
8
- has_many :revisions, :class_name => '::Recorder::Revision', :inverse_of => :item, :as => :item
9
- end
8
+ included do
9
+ has_many :revisions, :class_name => '::Recorder::Revision', :inverse_of => :item, :as => :item
10
+ end
10
11
 
11
- module ClassMethods
12
- def record_changes(options = {})
13
- after_commit :on => :create do
14
- Recorder::Tape.new(self, options).record_create
15
- end
12
+ module ClassMethods
13
+ def record_changes(options = {})
14
+ after_commit :on => :create do
15
+ Recorder::Tape.new(self, options).record_create
16
+ end
16
17
 
17
- after_commit :on => :update do
18
- Recorder::Tape.new(self, options).record_update
19
- end
18
+ after_commit :on => :update do
19
+ Recorder::Tape.new(self, options).record_update
20
+ end
20
21
 
21
- after_commit :on => :destroy do
22
- Recorder::Tape.new(self, options).record_destroy
22
+ after_commit :on => :destroy do
23
+ Recorder::Tape.new(self, options).record_destroy
24
+ end
23
25
  end
24
26
  end
25
27
  end
data/lib/recorder/tape.rb CHANGED
@@ -1,84 +1,85 @@
1
- class Recorder::Tape
1
+ module Recorder
2
+ class Tape
3
+ attr_reader :item, :options
2
4
 
3
- attr_reader :item, :options
4
-
5
- def initialize(item, options = {})
6
- @item = item
7
- @options = options
8
- end
5
+ def initialize(item, options = {})
6
+ @item = item
7
+ @options = options
8
+ end
9
9
 
10
- def record_create
11
- data = {
12
- :changes => self.sanitize_attributes(self.item.attributes)
13
- }
10
+ def record_create
11
+ data = {
12
+ :changes => self.sanitize_attributes(self.item.attributes)
13
+ }
14
14
 
15
- # changes.merge!(self.parse_associations_attributes)
15
+ # changes.merge!(self.parse_associations_attributes)
16
16
 
17
- if data.any?
18
- self.record(
19
- Recorder.store.merge({
20
- :event => :create,
21
- :data => data
22
- })
23
- )
17
+ if data.any?
18
+ self.record(
19
+ Recorder.store.merge({
20
+ :event => :create,
21
+ :data => data
22
+ })
23
+ )
24
+ end
24
25
  end
25
- end
26
26
 
27
- def record_update
28
- data = {
29
- :changes => self.sanitize_attributes(self.item.previous_changes)
30
- }
31
-
32
- associations = self.parse_associations_attributes
33
- data.merge!(:associations => self.parse_associations_attributes) if associations.any?
34
-
35
- if data.any?
36
- self.record(
37
- Recorder.store.merge({
38
- :event => :update,
39
- :data => data
40
- })
41
- )
27
+ def record_update
28
+ data = {
29
+ :changes => self.sanitize_attributes(self.item.previous_changes)
30
+ }
31
+
32
+ associations = self.parse_associations_attributes
33
+ data.merge!(:associations => self.parse_associations_attributes) if associations.any?
34
+
35
+ if data.any?
36
+ self.record(
37
+ Recorder.store.merge({
38
+ :event => :update,
39
+ :data => data
40
+ })
41
+ )
42
+ end
42
43
  end
43
- end
44
-
45
- def record_destroy
46
- end
47
44
 
48
- protected
49
-
50
- def record(params)
51
- params.merge!({
52
- :action_date => Date.today
53
- })
45
+ def record_destroy
46
+ end
54
47
 
55
- self.item.revisions.create(params)
56
- end
48
+ protected
57
49
 
58
- def sanitize_attributes(attributes = {})
59
- # attributes.symbolize_keys.delete_if{ |key, value| [:created_at, :updated_at, :delta].include?(key) || (value[0] == value[1]) }
60
- attributes.symbolize_keys.except(:created_at, :updated_at, :delta)
61
- end
50
+ def record(params)
51
+ params.merge!({
52
+ :action_date => Date.today
53
+ })
62
54
 
63
- def parse_associations_attributes
64
- if self.options[:associations].any?
65
- self.options[:associations].inject({}) do |hash, association|
66
- reflection = self.item.class.reflect_on_association(association)
67
- if reflection.present?
68
- if reflection.collection?
55
+ self.item.revisions.create(params)
56
+ end
69
57
 
70
- else
71
- object = self.item.send(association)
58
+ def sanitize_attributes(attributes = {})
59
+ # attributes.symbolize_keys.delete_if{ |key, value| [:created_at, :updated_at, :delta].include?(key) || (value[0] == value[1]) }
60
+ attributes.symbolize_keys.except(:created_at, :updated_at, :delta)
61
+ end
72
62
 
73
- if object.present? && self.sanitize_attributes(object.previous_changes).any?
74
- hash[reflection.name] = {
75
- :changes => self.sanitize_attributes(object.previous_changes)
76
- }
63
+ def parse_associations_attributes
64
+ if self.options[:associations].any?
65
+ self.options[:associations].inject({}) do |hash, association|
66
+ reflection = self.item.class.reflect_on_association(association)
67
+ if reflection.present?
68
+ if reflection.collection?
69
+
70
+ else
71
+ object = self.item.send(association)
72
+
73
+ if object.present? && self.sanitize_attributes(object.previous_changes).any?
74
+ hash[reflection.name] = {
75
+ :changes => self.sanitize_attributes(object.previous_changes)
76
+ }
77
+ end
77
78
  end
78
79
  end
79
- end
80
80
 
81
- hash
81
+ hash
82
+ end
82
83
  end
83
84
  end
84
85
  end
@@ -3,7 +3,7 @@ module Recorder
3
3
  module VERSION
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 1
6
+ TINY = 2
7
7
  PRE = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
data/lib/recorder.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'recorder/changeset'
2
1
  require 'recorder/version'
2
+ require 'recorder/changeset'
3
3
  require 'recorder/observer'
4
4
  require 'recorder/rails/controller_concern'
5
5
 
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Alexandrov