better_record 0.18.0 → 0.18.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aaabec32e93503cc3280479fb33a4b4e56ec33887ce430592730c6a42f61389
|
4
|
+
data.tar.gz: a02c353a6fa6a392c15cb8bed0710d5a49ee79c617db866e69c46974d4b23074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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)
|