order_cop 0.1.0 → 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: 83506d77c88c7d0fb5f3b5b0b779bdb33262adb7645951127fd2feb1668db52f
4
- data.tar.gz: ee2e8013a24a8078e87455a2aa88e98aae921137a870d9c3d29bdb1dbc067a76
3
+ metadata.gz: 9844113f7fde924bc0804ffd7a8a3e81b034e1009e2b8e399538e791756f1ba6
4
+ data.tar.gz: 71231522bb6415cb282945f68efcf58acc66d8f5400a70cbc039a076c49877ce
5
5
  SHA512:
6
- metadata.gz: 40dc1ee7a51ded6c68b4c44e68d0ce96c5a97f53ce95de5f68fb8651aab44c357f72564de56b623b853bba01867a8faf9dc7221c830a70ed5f961a1e61865a28
7
- data.tar.gz: 11eb778fdc25c1bbc1e164ec27a1c2738a2d3541d49b7c53a0a5e5ca8a13f06e07a298332a859080787eb0351281b2bb999b756532dde3aa4ac330bccf4a48b1
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.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/order_cop.rb CHANGED
@@ -54,16 +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
- puts "whitelisted #{lmethod}"
65
- return nil
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?
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gauthier Monserand