Skip to content

Instantly share code, notes, and snippets.

@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:37
Use RSpec tags to add behavior around specs.
# Add this to your spec_helper.rb
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].downcase.gsub(/\W+/, "_").split("_", 2).join("/")
VCR.use_cassette(name, :record => :new_episodes) do
example.call
end
end
end
require 'sinatra/base'
class MyApp < Sinatra::Base
@@my_app = {}
def self.new(*) self < MyApp ? super : Rack::URLMap.new(@@my_app) end
def self.map(url) @@my_app[url] = self end
class FooController < MyApp
map '/foo'
@terrbear
terrbear / write_deploy_log.rb
Created February 23, 2011 17:56
saves the deploy output up to the deployed location
alias :pputs :puts
def puts(str = "")
pputs(str)
$out << "#{str}"
end
STDOUT.instance_eval do
alias :pputs :puts
def puts(str = "")
pputs(str)
@mrrooijen
mrrooijen / gist:801418
Created January 29, 2011 01:59
Inherited Resources - Mongoid collection hack
##
# Option 1 (Probably best)
module MongoidActions
def collection
get_collection_ivar || set_collection_ivar(end_of_association_chain.all)
end
end
InheritedResources::Base.send :include, MongoidActions
@alg
alg / mongoid.rb
Created December 21, 2010 08:08
No underscore/dash escaping in Mongoid
# Instead of the standard composition, convert everything
# non-alpha and non-digit to dash and squeeze
class String
def identify
if Mongoid.parameterize_keys
gsub(/[^a-z0-9]+/, ' ').strip.gsub(' ', '-')
else
self
end
end
@ilpoldo
ilpoldo / templator.rb
Created September 2, 2010 14:30
My rails 3 app template
# Cleaning up and extending the Gemfile
remove_file 'Gemfile'
create_file 'Gemfile', <<-GEMFILE
source 'http://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Basic tagging system for mongoid documents.
# jpemberthy 2010
#
# class User
# include Mongoid::Document
# include Mongoid::Document::Taggable
# end
#
# @user = User.new(:name => "Bobby")
# @user.tag_list = "awesome, slick, hefty"