20 favorite ruby gems (ignite railsconf)
Post on 21-Oct-2014
2.646 views
DESCRIPTION
20 of my favorite Ruby gems, explained in 15 seconds per slide.TRANSCRIPT
authlogic
binarylogic
class UserSession < Authlogic::Session::Baseend
class ApplicationController < ActionController::Base private
def current_user_session UserSession.find end def current_user current_user_session && current_user_session.record end
bcrypt-ruby
codahale
require 'bcrypt'
class User < ActiveRecord::Base # users.password_hash in the database is a :string include BCrypt
def password @password ||= Password.new(password_hash) end
def password=(new_password) @password = Password.create(new_password) self.password_hash = @password endend
capybara
jnicklas
describe "the signup process", :type => :request do before :each do User.make(:email => '[email protected]', :password => 'caplin') end
it "signs me in" do within("#session") do fill_in 'Login', :with => '[email protected]' fill_in 'Password', :with => 'password' end click_link 'Sign in' endend
dim
jimweirich (gem-ified by me)
GameContainer = Dim::Container.new
GameContainer.register(:environment) { ENV['EXP_ENV'] }
GameContainer.register(:transmitter) do |c| Transmitter.new(c.environment) end
factory_girl
thoughtbot
Factory.define :simple_map, :parent => :map do |m| m.name "Simple Map" m.size 5
m.after_create do |map| map.with_grid do |grid| grid.add_feature(Terrain::Dirt,1,1,3,3) grid.add_feature(MapObjects::BlueCrystal,1,1) grid.add_feature(Landmarks::Mountain,4,4) end endend
context "saving and restoring" do it "preserves all data types in the grid" do map = Factory(:simple_map) map.feature_at(1,1).terrain.name.should == Terrain::Dirt endend
foreigner
matthuhiggins
add_foreign_key :maps, :terrain, :column => :default_terrain_id
formtastic
justinfrench
%h1 Sign Up
= semantic_form_for @user, :url => signup_path do |form| = form.semantic_errors
= form.inputs do = form.input :email, input_html: { autofocus: true } = form.input :identifier, :label => "In-Game Identifier" = form.input :password
= form.buttons do = form.commit_button "Signup"
girl_friday
mperham
QUEUE = GirlFriday::WorkQueue.new(:user_email, :size => 3) do |m| UserMailer.registration_email(m).deliverend
# while handling a web requestQUEUE.push(:email => @user.email, :name => @user.name)
grb
jinzhu
=> create new branch `branch` $ grb new [branch]
=> track branch $ grb track `branch`
=> add a remote repo $ grb remote_add `name` `repo path`
=> remove a remote repo $ grb remote_rm `name`
guard (guard-*)
thibaudgg
guard 'bundler' do watch('Gemfile')end
guard 'rspec' do watch(%r{^spec/.+_spec\.rb}) watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }end
guard 'coffeescript', :output => 'public/js/compiled' do watch(%r{^app/coffeescripts/.+\.coffee})end
jammit
documentcloud
embed_assets: ongzip_assets: onjavascript_compressor: yui
javascripts: workspace: - public/javascripts/vendor/jquery.js - public/javascripts/lib/*.js - public/javascripts/views/**/*.js - app/views/workspace/*.jst
stylesheets: common: - public/stylesheets/reset.css - public/stylesheets/widgets/*.css workspace: - public/stylesheets/pages/workspace.css empty: - public/stylesheets/pages/empty.css
omniauth
intridea
require 'oa-oauth'use OmniAuth::Strategies::Twitter, 'KEY', 'SECRET'
# redirect user to /auth/twitter# twitter redirects user to /auth/twitter/callback
get '/auth/twitter/callback' do auth_hash = request.env['omniauth.auth']end
ostruct*
*part of stdlib
require 'ostruct'
record = OpenStruct.newrecord.name = "John Smith"record.age = 70record.pension = 300
puts record.name # -> "John Smith"puts record.address # -> nil
perftools.rb
tmm1
pg_sexy_constraints
maxim
class AddConstraintsToBooks < ActiveRecord::Migration def self.up constrain :books do |t| t.title :not_blank => true, :alphanumeric => true t.isbn :unique => true, :blacklist => %w(badbook1) end endend
pusher
pusher
# serverPusher['a_channel'].trigger!('an_event', {:some => 'data'})
# client-side JS
var pusher = new Pusher('API_KEY');
pusher.subscribe('a_channel');pusher.bind('an_event', function(data) { console.info(data.some); // “data” });
right_aws
rightscale
query = ["['cat'=?] union ['dog'=?]", "clew", "Jon's boot"]sdb.query('family', query)
queue = RightAws::SqsGen2::Queue.create(sqs, 'my_cool_queue')msg = queue.receivemsg.visibility = 0queue.clear(true)queue.send_message('example')msg2 = queue.pop
spork
URL
Guard is now watching at '/Users/subelsky/code/exp-world'Starting Spork for RSpec
Spork server for RSpec successfully startedGuard::RSpec is running, with RSpec 2!Running all specsUsing RSpecLoading Spork.prefork block...........................................................
Finished in 2 seconds74 examples, 0 failures
therubyracer
cowboyd
require 'v8'
cxt = V8::Context.newcxt.eval('parseInt("50",10)') # => 50
cxt["say"] = lambda { |word, times| word * times }cxt.eval("say('Hello', 3)") # => HelloHelloHello
timecop
jtrupiano
joe = User.find(1)joe.purchase_home()assert !joe.mortgage_due?
# move ahead a month and assert that the mortgage is dueTimecop.freeze(Date.today + 30) do assert joe.mortgage_due?end