Description¶ ↑
Blazy(be lazy) is a fluent extension to active record models to reduce number of key strokes in rails console.
For rails 2.x refer to v0.1.2
Install¶ ↑
gem install blazy
Usage¶ ↑
Add dependency in gem file
gem ‘blazy’, :group => :development
Go to rails console in your rails project and type
Blazy.init
you are ready to go!!
How does it help me?¶ ↑
Most of the operations we do in rails console while debugging a problem or looking for model values in database take a lot of key strokes. Blazy provides methods, aliases and a fluent interface to reduce the number of keystrokes to bare minimal.
Examples¶ ↑
Lets say you have a active record model called Project.
This is what being lazy means
Project.find(11) –> Project-11 or Project # [id] is preferred Project.all –> projects Project.first –> project
When you want to see some subset of data
Project.all(:limit => 10) –> 10.projects Project.first –> 1.project
Scopes generated for each column
Project.where(:name => ‘blazy’) –> Project.with_name(‘blazy’) # you get autocomplete for this
And chaining them
10.projects.where(‘priority < 2’).order(:priority) Project.with_priority(1).limit 10
Lastly and actually the least some aliases. These are useful at the end of scope to inspect a model
Project.with_priority(1).f.name
Listing them –> f => first, l => last, a => all
To do¶ ↑
models - to list all models in the project relations - to show quick summary of a model’s associations
Other useful gems in script/console¶ ↑
and add this to your ~/.irbc