SmartLogic Logo (443) 451-3001

Blog

Timecop 0.3.4 Released

December 7th, 2009 by

Timecop 0.3.4 has just been released. To install simply run: gem install timecop.

Timecop is a RubyGem providing “time travel” and “time freezing” capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.

Documentation is hosted at RubyForge. The source code is hosted at GitHub.

Updates include:

Read the rest of this entry »

Rack::Rewrite + Google Analytics Makes Site Transitions Seamless

November 24th, 2009 by

At SmartLogic we recently rebuilt our website in rails. The previous version was a MediaWiki installation with a ton of content that had garnered a decent bit of Google juice that we did not want to lose. By setting up 301 permanent redirects for the old URL’s, we can hold onto that juice.

Read the rest of this entry »

Rack::Rewrite for Site Maintenance and Downtime

November 16th, 2009 by

Rack::Rewrite is a Rack middleware for defining and applying rewrite rules. Though it’s not a full replacement for Apache’s mod_rewrite, a great deal of rules I’ve previously written in Apache config files can be replaced by Rack::Rewrite. Run gem install rack-rewrite to install the gem.

I typically leverage rewrite rules to take my sites offline for maintenance. Most capistrano users will be familiar with the following Apache rewrite ruleset.
Read the rest of this entry »

DRY up your Controllers with find_or_redirect

October 23rd, 2009 by

Do you do this:

  class ModelsController < ApplicationController
    before_filter :find_model
    def show
    end
 
    def destroy
      @model.destroy
    end
 
    private
 
    def find_model
      @model = Model.find_by_id(params[:id])
      unless @model
        redirect_to :action => :index
        flash[:error] = "Invalid model id"
        return false
      end
    end
  end

in every controller? Gets repetitive doesn’t it?
Read the rest of this entry »

Timecop 0.3.0 Released

September 20th, 2009 by

Timecop 0.3.0 has just been released. To install simply run: gem install timecop.

Timecop is a RubyGem providing “time travel” and “time freezing” capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.

Documentation is on RubyForge. The source code is hosted at GitHub.

Updates include:

API

  • Completely remove Timecop#unset_all (deprecated by Timecop#return in 0.2.0)
  • Return Time.now from #freeze, #travel and #return — code contributed by Keith Bennett (keithrbennett)

Maintenance

  • Fix bug that left Time#mock_time set in some instances
  • Upped build dependency to jeweler ~> 1.2.1
  • Don’t pollute top-level namespace with classes/constants

Documentation

  • Clearer examples in the README, better description in the gemspec
  • Improve RDoc

Shell Script to Upgrade Ruby Enterprise Edition while Maintaining Directory Naming Sanity

June 10th, 2009 by

As you’re likely already aware, a denial of service (DoS) vulnerability in Ruby’s BigDecimal library was uncovered, fixed and reported on June 9, 2009. Patching options include:

Read the rest of this entry »

Including external .rake files in your project’s Rakefile — keep your rake tasks organized!

May 26th, 2009 by

Perhaps you have a non-Rails project (let’s say it’s in ruby and maybe some other languages, too) and you use Rake tasks to automate some of the dirty work. So you’ve got a bunch of methods that you wish to keep neatly sorted into .rake files in some dir’s (probably a sub folder of lib like lib/tasks) and a single Rakefile in your project’s root directory. Including those external .rake files in your project’s Rakefile via require statements won’t work :

require 'lib/some_rake_file' # or require 'lib/some_rake_file.rake'

=> rake aborted!
no such file to load — /home/your_project/lib/some_rake_file

Rake assumes the ‘require’d files end in .rb, so it won’t find your .rake files. You need to import rake files:

import 'lib/some_rake_file'

This is fine for individual files, but I wanted to include all files that end in .rake in my tasks dir:

Dir.glob('tasks/*.rake').each { |r| import r }

…and there you go. While dead simple, this exemplifies an important distinction between require and import that I found to be poorly documented. Keep your rake tasks organized and remember that Rake isn’t just for rails apps!

Find the Unique Sessions for a Rails Application

May 4th, 2009 by

Today we’re going to look at how to find the number of unique sessions over a specific time frame for a rails application. We’ll be using the slow-actions gem.

Read the rest of this entry »

Using Sanitize Email to Preview HTML Emails Locally

April 30th, 2009 by

John Trupiano has a great post to get you started with sanitize_email for Ruby on Rails.

I wanted to preview my HTML emails without having to fill up my online email inboxes with tons of email (and then I’d have to make filters too). I also didn’t want to manage actually sending real email. So, I set up my machine for local delivery. Read on for instructions.
Read the rest of this entry »

Integrity CI on Passenger 2.2.2 with Ruby Enterprise Edition on Ubuntu 8.04

April 26th, 2009 by

I just spent a few hours trying to get this configuration sorted out, so I thought I’d share my notes. My goal was to get Integrity running on Passenger with Ruby Enterprise Edition. However, I couldn’t get the user Integrity/Apache was running as to use the proper PATH.

Whenever Integrity would try to build my project, I’d get an error about rake not being able to be found: sh: rake: not found

Read the rest of this entry »

  • You are currently browsing the archives for the Ruby category.