order_cop 0.1.1 → 0.1.2

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: eec6b83744b3873a01b1e5bbc3babf32c5d7a0ba76608b0aeacdd91094263eb2
4
- data.tar.gz: 3c2a4a792e2670544a4cd327ee094aab10f8212a3017cb937464ee3e3cea0dec
3
+ metadata.gz: 9844113f7fde924bc0804ffd7a8a3e81b034e1009e2b8e399538e791756f1ba6
4
+ data.tar.gz: 71231522bb6415cb282945f68efcf58acc66d8f5400a70cbc039a076c49877ce
5
5
  SHA512:
6
- metadata.gz: f3e2281df0bbbc4ed5e17a9b2fb671b91af40c016fde050a6bb23d2969feee877b62c720255f49de9544756472692fb9df4fa8d957ff97540821263a31693d4b
7
- data.tar.gz: 3247b3dc2bd877226cd03437acb5cac3bf66712d7a7bfdc5d17357a41460dcf5783e265667394c1df0055958be2c7a3bcfa18cc534127761eb20dedf59a308d3
6
+ metadata.gz: 874cf90c0aefe66aa65a936bf2f48ee2fb2b383c41d5b137af448a5fafbabd5c138940254481ae27a36ea59c004692ca5d75cdc6e61104a6cebd81dfa676226f
7
+ data.tar.gz: ca59878e2544b486200256d224b5fc99ec0433ee134ea2617f46db658880f3860c42e316391b77afd332b7077fe073d51cd95db2758aaccaf2e5ba813c944cf7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- order_cop (0.1.0)
4
+ order_cop (0.1.2)
5
5
  binding_of_caller (~> 1.0)
6
6
  rails (~> 7.0)
7
7
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrderCop
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/order_cop.rb CHANGED
@@ -54,15 +54,29 @@ module OrderCop
54
54
 
55
55
  private
56
56
 
57
- def detect_missing_order(method)
58
- return if OrderCop.disabled?
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
- return nil
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?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: order_cop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gauthier Monserand