better_record 0.18.0 → 0.18.1

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
  SHA256:
3
- metadata.gz: c07da71971172205aecfda94df6fb1ca1213d32569053fcd8892dda8a91076fa
4
- data.tar.gz: a64508bffff376045804d34726d45bfa6a0ab80948f45198dac6a6c1a8a57d5f
3
+ metadata.gz: 6aaabec32e93503cc3280479fb33a4b4e56ec33887ce430592730c6a42f61389
4
+ data.tar.gz: a02c353a6fa6a392c15cb8bed0710d5a49ee79c617db866e69c46974d4b23074
5
5
  SHA512:
6
- metadata.gz: b47ff7753e4775cd1d95f4741833e4719e51d0c4624d5139b68828c84c51e40eaeece53dcd60ac5052b288f83d3f6ca8689c3a7b0ca7fcdbcf0cd8ee8259d5b9
7
- data.tar.gz: 0ccc0c6aab836bba068ba45d014555b4bb08d8cf88b27a9d673489d0c36fcd6d3f5fa016525797e6ee57c3da2b150c36663f5a2b5b450410ecb06749b11a02fb
6
+ metadata.gz: 96baad4e4a3813d71771bec10b5432f6bdb0bdea299c77a137ceae5cebe2ddb1ac64f1535e0cd8a3a756841b3ce57700d2e88a0cb9fe1de8c27bd31f7dbff3ef
7
+ data.tar.gz: a173fe808cacd7ccc6ee502a8cc8e05a156bf40001071e867a668948a976891177fd49ff47a24edd302d4221443106400451c1cc22e8d6a8a2659710ba048631
@@ -13,50 +13,7 @@ module BetterRecord
13
13
  # == Extensions ===========================================================
14
14
 
15
15
  # == Relationships ========================================================
16
- if (ha = BetterRecord.has_auditing_relation_by_default)
17
- class << self
18
- define_method BetterRecord.audit_relation_name do |*args, &block|
19
- @logger_model ||=
20
- begin
21
- connection.execute(%Q(SELECT 1 FROM #{BetterRecord::LoggedAction.table_name}_#{self.table_name} LIMIT 1))
22
-
23
- class self.to_s.constantize::LoggedAction < BetterRecord::LoggedAction
24
- self.table_name = "#{BetterRecord::LoggedAction.table_name}_#{self.to_s.deconstantize.constantize.table_name}"
25
- self
26
- end
27
- rescue ActiveRecord::StatementInvalid
28
- class self.to_s.constantize::LoggedAction < BetterRecord::LoggedAction
29
- self
30
- end
31
- end
32
-
33
- return @logger_model if args.present? && args.first == 'SETTING_INHERITANCE'
34
16
 
35
- base_q = @logger_model.where(table_name: self.table_name)
36
- base_q = base_q.where(*args) if args.present?
37
-
38
- if block
39
- base_q.split_batches do |b|
40
- b.each do |r|
41
- block.call(r)
42
- end
43
- end
44
- else
45
- base_q
46
- end
47
- end
48
- end
49
-
50
- def self.inherited(child)
51
- super
52
- TracePoint.trace(:end) do |t|
53
- if child == t.self
54
- child.set_audits_methods!
55
- t.disable
56
- end
57
- end
58
- end
59
- end
60
17
  # == Validations ==========================================================
61
18
 
62
19
  # == Scopes ===============================================================
@@ -66,7 +23,7 @@ module BetterRecord
66
23
  # == Boolean Class Methods ================================================
67
24
 
68
25
  # == Class Methods ========================================================
69
- def self.set_audits_methods!
26
+ def self.set_audit_methods!
70
27
  m = __send__ BetterRecord.audit_relation_name, 'SETTING_INHERITANCE'
71
28
  self.has_many self.audit_relation_name,
72
29
  class_name: m.to_s,
@@ -108,5 +65,47 @@ module BetterRecord
108
65
  end
109
66
 
110
67
 
68
+ if (ha = BetterRecord.has_auditing_relation_by_default)
69
+ has_many self.audit_relation_name,
70
+ class_name: 'BetterRecord::LoggedAction',
71
+ primary_type: :table_name,
72
+ foreign_key: :row_id,
73
+ foreign_type: :table_name,
74
+ as: self.audit_relation_name
75
+
76
+ class << self
77
+ define_method BetterRecord.audit_relation_name do |*args, &block|
78
+ @logger_model ||=
79
+ begin
80
+ connection.execute(%Q(SELECT 1 FROM #{BetterRecord::LoggedAction.table_name}_#{self.table_name} LIMIT 1))
81
+
82
+ class self.to_s.constantize::LoggedAction < BetterRecord::LoggedAction
83
+ self.table_name = "#{BetterRecord::LoggedAction.table_name}_#{self.to_s.deconstantize.constantize.table_name}"
84
+ self
85
+ end
86
+ rescue ActiveRecord::StatementInvalid
87
+ class self.to_s.constantize::LoggedAction < BetterRecord::LoggedAction
88
+ self
89
+ end
90
+ end
91
+
92
+ return @logger_model if args.present? && args.first == 'SETTING_INHERITANCE'
93
+
94
+ base_q = @logger_model.where(table_name: self.table_name)
95
+ base_q = base_q.where(*args) if args.present?
96
+
97
+ if block
98
+ base_q.split_batches do |b|
99
+ b.each do |r|
100
+ block.call(r)
101
+ end
102
+ end
103
+ else
104
+ base_q
105
+ end
106
+ end
107
+ end
108
+ end
109
+
111
110
  end
112
111
  end
@@ -21,7 +21,8 @@ module BetterRecord
21
21
  polymorphic: :true,
22
22
  primary_type: :table_name,
23
23
  foreign_key: :row_id,
24
- foreign_type: :table_name
24
+ foreign_type: :table_name,
25
+ optional: true
25
26
 
26
27
  # == Validations ==========================================================
27
28
 
@@ -90,7 +90,10 @@ class UpdateBetterRecordAuditFunctions < ActiveRecord::Migration[5.2]
90
90
 
91
91
  klass = Class.new(BetterRecord::LoggedAction)
92
92
  klass.table_name = "#{BetterRecord.db_audit_schema}.logged_actions_#\{r.table_name}"
93
+ BetterRecord.const_set(:NewLoggedAction, klass)
94
+ BetterRecord::NewLoggedAction
93
95
  rescue ActiveRecord::StatementInvalid
96
+ BetterRecord.const_set(:NewLoggedAction, nil)
94
97
  klass = BetterRecord::LoggedAction
95
98
  end
96
99
  klass.create!(r.attributes)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BetterRecord
4
- VERSION = '0.18.0'
4
+ VERSION = '0.18.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley