Class: ActiveRecordInstanceCount::Middleware
- Inherits:
-
Object
- Object
- ActiveRecordInstanceCount::Middleware
- Defined in:
- lib/active-record-instance-count.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
- #log_activerecord ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
7 8 9 10 11 12 13 14 |
# File 'lib/active-record-instance-count.rb', line 7 def initialize(app, = {}) @app = app unless [:logger] raise 'Missing options[:logger] argument' end @logger = [:logger] ActiveRecord::Base.send(:include, ActiveRecordInstanceCount::Instrumentation::ActiveRecord) end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 |
# File 'lib/active-record-instance-count.rb', line 16 def call(env) status, headers, body = @app.call(env) log_activerecord [status, headers, body] end |
#log_activerecord ⇒ Object
22 23 24 25 26 27 |
# File 'lib/active-record-instance-count.rb', line 22 def log_activerecord sorted_list = ActiveRecordInstanceCount::HashUtils.to_sorted_array(ActiveRecord::Base.instantiated_hash) sorted_list.unshift("Total: #{ActiveRecord::Base.total_objects_instantiated}") @logger.info("Instantiation Breakdown: #{sorted_list.join(' | ')}") reset_objects_instantiated end |