Let's look at an innocuous piece of ruby. Consider some view code showing a user's name and phone number:
"#{first_name} #{last_name} #{phone}"Great - this is very succinct, readable, and can easily be extracted to a method in a
| # Example usage: | |
| # timeplot User.all | |
| # timeplot User.all, bucket_size: day, field: :updated_at | |
| # | |
| # Arguments: | |
| # bucket_size: One of [:day, :month, :year]. Defaults to :month. | |
| # field: Timestamp field to plot against. Defaults to :created_at. | |
| class TimePlot | |
| BUCKET_SIZES = [:day, :month, :year] | |
| X_AXIS_MAX = 100 |
| puts "WARN: We are patching rake tasks to support postgres. You have upgraded Rails and may not need this patch any more (lib/tasks/postgres.rake)." if Rails.version > "3.2.8" | |
| namespace :db do | |
| desc 'kills connections to postgres db' | |
| task :kill_postgres_connections => :environment do | |
| env = ENV['RAILS_ENV'] | |
| db_config = Rails.configuration.database_configuration[env] | |
| fail(ArgumentError, "Could not find db config entry for env (#{env})") unless db_config | |
| db_name = db_config['database'] |