This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| alias :pputs :puts | |
| def puts(str = "") | |
| pputs(str) | |
| $out << "#{str}" | |
| end | |
| STDOUT.instance_eval do | |
| alias :pputs :puts | |
| def puts(str = "") | |
| pputs(str) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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" |
NewerOlder