models_auditor 1.0.6 → 1.0.7

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: 798b2ce9bbeff3dcf829c00e38160fe960e4a859
4
- data.tar.gz: 413c51cb3cd244947eaaa018a2888b8a0ec11b78
3
+ metadata.gz: 8259cff8a18e95707305268e2d5344f500c9c1ba
4
+ data.tar.gz: 3aaa9d4ab21d8c91016ff11f29ec18755708efc1
5
5
  SHA512:
6
- metadata.gz: dc1360fbfa0a78fca9217e99610a56e121e6efcea0e617356e4ed01148586d6c29a30612bd225917efc8c7a2da846ce4b0d4827d115ecc525d8850db2e1fe8e4
7
- data.tar.gz: f872f90f9657606ee1be07db44673172e05af11b11c90a75c4af2a802816cdf84e336df39870d4242748448a062f8f95958a8d1a37cc9db34d60df31b6164eb3
6
+ metadata.gz: 3949ea27aa765cfc676eb3934e275a060375e2a28c40e33e729d533287496170d40dcf78faf229f2e70bb578ccb4e60041fd0472b346d0f73acb86e85c525e01
7
+ data.tar.gz: 3974017de3335b66d217bf7f03ab899cb39fc915b1928b20f03aa51b3d069c16db54732a7ac37fe4c4ae31ea19c9fb3a945602ec998cc825c3b8a5bbfc21615c
@@ -21,18 +21,49 @@ module ModelsAuditor
21
21
  end
22
22
 
23
23
  module InstanceMethods
24
+ def is_audit_enabled?
25
+ self.class.instance_variable_get(:@audit_enabled) ||
26
+ (self.class.column_names.include?(self.class.inheritance_column) &&
27
+ self.class.superclass.instance_variable_get(:@audit_enabled))
28
+ end
29
+
30
+ def get_audit_mode
31
+ mode = self.class.instance_variable_get(:@audit_mode)
32
+ if mode.nil?
33
+ self.class.column_names.include?(self.class.inheritance_column) &&
34
+ self.class.superclass.instance_variable_get(:@audit_enabled) ?
35
+ self.class.superclass.instance_variable_get(:@audit_mode) :
36
+ nil
37
+ else
38
+ mode
39
+ end
40
+ end
41
+
42
+ def get_audit_options
43
+ settings = self.class.instance_variable_get(:@audit_settings)
44
+ if settings.nil?
45
+ self.class.column_names.include?(self.class.inheritance_column) &&
46
+ self.class.superclass.instance_variable_get(:@audit_enabled) ?
47
+ self.class.superclass.instance_variable_get(:@audit_settings) :
48
+ {}
49
+ else
50
+ settings
51
+ end
52
+ end
53
+
24
54
  def do_audit_init_snapshot
25
55
  return unless ModelsAuditor.config.audit_enabled
26
- mode = self.class.instance_variable_get(:@audit_mode)
27
- return unless self.class.instance_variable_get(:@audit_enabled) && AUDIT_SNAPSHOT_MODES.include?(mode)
56
+ return unless is_audit_enabled?
57
+ mode = get_audit_mode
58
+ return unless AUDIT_SNAPSHOT_MODES.include?(mode)
28
59
  ma_store_initial_state(ModelsAuditor.store)
29
60
  end
30
61
 
31
62
  def do_audit_process
32
63
  return unless ModelsAuditor.config.audit_enabled
33
- return unless self.class.instance_variable_get(:@audit_enabled)
34
- mode = self.class.instance_variable_get(:@audit_mode)
35
- options = self.class.instance_variable_get(:@audit_settings) || {}
64
+ return unless is_audit_enabled?
65
+ mode = get_audit_mode
66
+ options = get_audit_options
36
67
  store = ModelsAuditor.store
37
68
 
38
69
  initial_data = ma_get_initial_state(store)
@@ -135,9 +166,9 @@ module ModelsAuditor
135
166
 
136
167
  # Получает сериализованные данные для аудита
137
168
  def ma_auditor_get_data
138
- options = self.class.instance_variable_get(:@audit_settings) || {}
169
+ options = get_audit_options
139
170
  audit_params = options[:params]
140
- mode = self.class.instance_variable_get(:@audit_mode)
171
+ mode = get_audit_mode
141
172
  case mode
142
173
  when AUDIT_MODE_JSON
143
174
  self.as_json(audit_params)
@@ -157,7 +188,7 @@ module ModelsAuditor
157
188
  when AUDIT_MODE_CHANGES_ONLY
158
189
  self.previous_changes
159
190
  else
160
- raise ArgumentError.new('Incorrect value of argument audit_type')
191
+ raise ArgumentError.new("Incorrect value of argument audit_type #{mode}")
161
192
  end
162
193
  end
163
194
  end
@@ -1,3 +1,3 @@
1
1
  module ModelsAuditor
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: models_auditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Gorbunov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-17 00:00:00.000000000 Z
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails