20 favorite ruby gems (ignite railsconf)

20
authlogic binarylogic class UserSession < Authlogic::Session::Base end class ApplicationController < ActionController::Base private def current_user_session UserSession.find end def current_user current_user_session && current_user_session.record end

Post on 21-Oct-2014

2.646 views

Category:

Technology


6 download

DESCRIPTION

20 of my favorite Ruby gems, explained in 15 seconds per slide.

TRANSCRIPT

Page 1: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 2: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 3: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 4: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 5: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 6: 20 Favorite Ruby Gems (Ignite RailsConf)

foreigner

matthuhiggins

add_foreign_key :maps, :terrain, :column => :default_terrain_id

Page 7: 20 Favorite Ruby Gems (Ignite RailsConf)

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"

Page 8: 20 Favorite Ruby Gems (Ignite RailsConf)

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)

Page 9: 20 Favorite Ruby Gems (Ignite RailsConf)

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`

Page 10: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 11: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 12: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 13: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 14: 20 Favorite Ruby Gems (Ignite RailsConf)

perftools.rb

tmm1

Page 15: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 16: 20 Favorite Ruby Gems (Ignite RailsConf)

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” });

Page 17: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 18: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 19: 20 Favorite Ruby Gems (Ignite RailsConf)

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

Page 20: 20 Favorite Ruby Gems (Ignite RailsConf)

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