order_cop 0.1.0 → 0.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/order_cop/version.rb +1 -1
- data/lib/order_cop.rb +23 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9844113f7fde924bc0804ffd7a8a3e81b034e1009e2b8e399538e791756f1ba6
|
4
|
+
data.tar.gz: 71231522bb6415cb282945f68efcf58acc66d8f5400a70cbc039a076c49877ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 874cf90c0aefe66aa65a936bf2f48ee2fb2b383c41d5b137af448a5fafbabd5c138940254481ae27a36ea59c004692ca5d75cdc6e61104a6cebd81dfa676226f
|
7
|
+
data.tar.gz: ca59878e2544b486200256d224b5fc99ec0433ee134ea2617f46db658880f3860c42e316391b77afd332b7077fe073d51cd95db2758aaccaf2e5ba813c944cf7
|
data/Gemfile.lock
CHANGED
data/lib/order_cop/version.rb
CHANGED
data/lib/order_cop.rb
CHANGED
@@ -54,16 +54,29 @@ module OrderCop
|
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
def
|
58
|
-
|
59
|
-
level = 1.upto(binding.frame_count).find do |i|
|
57
|
+
def stack_is_whitelisted?
|
58
|
+
1.upto(binding.frame_count).each do |i|
|
60
59
|
lbinding = binding.of_caller(i)
|
61
60
|
lmethod = lbinding.eval("__method__")
|
62
61
|
next if lmethod.nil?
|
62
|
+
puts "lmethod: #{lmethod}" if OrderCop.debug?
|
63
63
|
if OrderCop::WHITELIST.include?(lmethod)
|
64
|
-
puts "
|
65
|
-
return
|
64
|
+
puts "#{lmethod} is whitelisted, ignoring" if OrderCop.debug?
|
65
|
+
return true
|
66
66
|
end
|
67
|
+
end
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
def detect_missing_order(method)
|
72
|
+
return if OrderCop.disabled?
|
73
|
+
puts "missing order, detect if allowed" if OrderCop.debug?
|
74
|
+
puts "stack size: #{binding.frame_count}" if OrderCop.debug?
|
75
|
+
|
76
|
+
return if stack_is_whitelisted?
|
77
|
+
|
78
|
+
level = 1.upto(binding.frame_count).find do |i|
|
79
|
+
lbinding = binding.of_caller(i)
|
67
80
|
location = lbinding.source_location[0]
|
68
81
|
location.include?(Rails.root.to_s) && !location.include?(Rails.root.join("config").to_s)
|
69
82
|
end
|
@@ -135,8 +148,12 @@ module OrderCop
|
|
135
148
|
config.raise
|
136
149
|
end
|
137
150
|
|
151
|
+
def self.debug?
|
152
|
+
config.debug
|
153
|
+
end
|
154
|
+
|
138
155
|
def self.config(**options)
|
139
|
-
@config ||= OpenStruct.new(rails_logger: false, raise: true, enabled: true)
|
156
|
+
@config ||= OpenStruct.new(rails_logger: false, raise: true, enabled: true, debug: false)
|
140
157
|
options.each do |k, v|
|
141
158
|
@config[k] = v
|
142
159
|
end
|
@@ -170,4 +187,3 @@ end
|
|
170
187
|
ActiveSupport::Reloader.to_prepare do
|
171
188
|
OrderCop.apply(Rails.application)
|
172
189
|
end
|
173
|
-
# OrderCop.setup(rails_logger: true) unless Rails.env.production?
|