Project

aroi

0.03
No commit activity in last 3 years
No release in over 3 years
ActiveRecord Object Instrumenter: Instrument the creation of ActiveRecord objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.16
>= 0
>= 0

Runtime

 Project Readme

aroi

Build Status

(A)ctive (R)ecord (O)bject (I)nstrumenter

Adds ActiveSupport::Notifications instrument calls to the creation of any ActiveRecord object.

Usage

Include the gem

gem 'aroi'
```

Bundle your app and add a rails initializer

```` ruby
# config/initializers/aroi.rb

Aroi::Instrumentation.instrument_creation!

ActiveSupport::Notifications.subscribe(/instance.active_record/) do |name, start, finish, id, payload|
  # name, start, finish, id are all the same as usual for notifications
  puts "Created a #{payload[:name]} object"
end

aroi will dispatch 'instance.active_record' any time an ActiveRecord object is instantiated.

See the ActiveSupport::Notifications docs for more information on how to subscribe to instrumented notifications.

Why

Rails 3 brought about ActiveSupport::Notifications as a way to subscribe to different actions that happen within your rails application. You can use it to instrument how long a controller action takes, how much of that time was spent creating views verses querying the DB. At times it may be worth instrumenting the number of ActiveRecord objects that have been created per controller action. This gem provides the foundation to doing so.

Credit

Heavily inspired by Oink. oink does some great things with logging. We borrow some of those ideas but fire off ActiveSupport::Notifications instead of logging.

Contributing

  1. Fork it ( https://github.com/instructure/aroi/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request