order_cop 0.1.1 → 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 -6
- 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,15 +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
|
-
|
64
|
+
puts "#{lmethod} is whitelisted, ignoring" if OrderCop.debug?
|
65
|
+
return true
|
65
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)
|
66
80
|
location = lbinding.source_location[0]
|
67
81
|
location.include?(Rails.root.to_s) && !location.include?(Rails.root.join("config").to_s)
|
68
82
|
end
|
@@ -134,8 +148,12 @@ module OrderCop
|
|
134
148
|
config.raise
|
135
149
|
end
|
136
150
|
|
151
|
+
def self.debug?
|
152
|
+
config.debug
|
153
|
+
end
|
154
|
+
|
137
155
|
def self.config(**options)
|
138
|
-
@config ||= OpenStruct.new(rails_logger: false, raise: true, enabled: true)
|
156
|
+
@config ||= OpenStruct.new(rails_logger: false, raise: true, enabled: true, debug: false)
|
139
157
|
options.each do |k, v|
|
140
158
|
@config[k] = v
|
141
159
|
end
|
@@ -169,4 +187,3 @@ end
|
|
169
187
|
ActiveSupport::Reloader.to_prepare do
|
170
188
|
OrderCop.apply(Rails.application)
|
171
189
|
end
|
172
|
-
# OrderCop.setup(rails_logger: true) unless Rails.env.production?
|