Class: RSpec::SQLimit::Counter
- Inherits:
-
Object
- Object
- RSpec::SQLimit::Counter
- Defined in:
- lib/rspec/sqlimit/counter.rb
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #count ⇒ Object
-
#initialize(matcher, block) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(matcher, block) ⇒ Counter
Returns a new instance of Counter.
9 10 11 12 13 14 |
# File 'lib/rspec/sqlimit/counter.rb', line 9 def initialize(matcher, block) @queries = [] @matcher = matcher @block = block @mutex = Mutex.new end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
3 4 5 |
# File 'lib/rspec/sqlimit/counter.rb', line 3 def matcher @matcher end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
3 4 5 |
# File 'lib/rspec/sqlimit/counter.rb', line 3 def queries @queries end |
Class Method Details
.[](*args) ⇒ Object
5 6 7 |
# File 'lib/rspec/sqlimit/counter.rb', line 5 def self.[](*args) new(*args).tap(&:call) end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/rspec/sqlimit/counter.rb', line 16 def call @mutex.synchronize do @queries = [] ActiveSupport::Notifications.subscribed callback, "sql.active_record" do @block.call end end end |
#count ⇒ Object
25 26 27 |
# File 'lib/rspec/sqlimit/counter.rb', line 25 def count matcher ? queries.count { |query| query[:sql] =~ matcher } : queries.count end |