ruby isn't just about rails

46
Adam Wiggins Codemash 2009 Ruby Isn’t Just About Rails

Post on 12-Sep-2014

9.077 views

Category:

Technology


2 download

DESCRIPTION

A whirlwind tour of the Rails-inspired Ruby ecosystem which has been frantically innovating for the past several years.

TRANSCRIPT

Page 1: Ruby Isn't Just About Rails

Adam WigginsCodemash 2009

Ruby Isn’tJust About Rails

Page 2: Ruby Isn't Just About Rails

?

Page 3: Ruby Isn't Just About Rails

Ruby?

Page 4: Ruby Isn't Just About Rails
Page 5: Ruby Isn't Just About Rails
Page 6: Ruby Isn't Just About Rails

You can’t sell a platform

Page 7: Ruby Isn't Just About Rails

You can’t sell a platform

...without a killer app.

Page 8: Ruby Isn't Just About Rails

A programming language is a platform

Page 9: Ruby Isn't Just About Rails

isthe killer appfor Ruby

Page 10: Ruby Isn't Just About Rails

Came for Rails,stayed for Ruby

Page 11: Ruby Isn't Just About Rails

An explosion of Ruby projects in the past 2 years

Page 12: Ruby Isn't Just About Rails

Let’s take a tour!

Page 13: Ruby Isn't Just About Rails

Rails is:ORM - ActiveRecordWeb Layer - ActionPackTemplating - ERBTest Framework - Test::Unit

Page 14: Ruby Isn't Just About Rails

ORM

ActiveRecord

Page 15: Ruby Isn't Just About Rails

class CreatePosts < ActiveRecord::Migration create_table :posts do |t| t.string :title t.text :body t.datetime :created_at t.integer :post_id endend

$ rake db:migrate

class Post < ActiveRecord::Base has_many :commentsend

Post.find(:first, :conditions => [ "title = ?", "First post" ])

Page 16: Ruby Isn't Just About Rails

ORM

ActiveRecord

DataMapper

Sequel

Page 17: Ruby Isn't Just About Rails

Define schema in the code instead of the database

http://datamapper.org

Page 18: Ruby Isn't Just About Rails

class Post include DataMapper::Resource

property :id, Serial property :title, String property :body, Text property :created_at, DateTime

has n, :commentsend

DataMapper.auto_upgrade!

Post.first(:title => "First Post")

Page 19: Ruby Isn't Just About Rails

Access a database with just hashes - or map models

http://sequel.rubyforge.org

Page 20: Ruby Isn't Just About Rails

db = Sequel.connect('mysql://root@localhost/db')

db.create_table :posts do primary_key :id varchar :title text :body datetime :created_atend

db[:posts].filter(:title => "First Post").first

Page 21: Ruby Isn't Just About Rails

Web Layer

ActionPack

Page 22: Ruby Isn't Just About Rails

ActionController::Routing::Routes.draw do |map| map.resource :postsend

class PostsController < ApplicationController def create @post = Post.create! params redirect_to(@post) end

def show @post = Post.find(params[:id]) endend

Page 23: Ruby Isn't Just About Rails

Web Layer

ActionPack

Merb

Sinatra

Page 24: Ruby Isn't Just About Rails

“No code is faster than no code”

The hacker’s framework

http://merbivore.org

Page 25: Ruby Isn't Just About Rails

Merb::Router.prepare do |router| resource :postsend

class Posts < Merb::Controller def create @post = Post.create params redirect(url(:post, @post)) end

def show @post = Post.find(params[:id]) display @post endend

Page 26: Ruby Isn't Just About Rails

use_orm :datamapper use_test :rspec use_template_engine :erb

Page 27: Ruby Isn't Just About Rails

Merb 2.0 == Rails 3.0

Page 28: Ruby Isn't Just About Rails

“Exposed simplicity instead of hidden complexity”

The classy microframework for Ruby

http://sinatra.rubyforge.org

Sinatra

Page 29: Ruby Isn't Just About Rails

require 'rubygems'require 'sinatra'require 'lib/posts'

post '/posts' post = Post.create! params redirect "/posts/#{post.id}"end

get '/posts/:id' do @post = Post.find(params[:id]) erb :postend

Page 30: Ruby Isn't Just About Rails

Test Framework

Page 31: Ruby Isn't Just About Rails

Unit tests

Page 32: Ruby Isn't Just About Rails

TDDTest-Driven Development

Page 33: Ruby Isn't Just About Rails

BDDBehavior-Driven Development

http://behaviour-driven.org

Page 34: Ruby Isn't Just About Rails

TATFTTest All The Darn Time

Page 35: Ruby Isn't Just About Rails

Test Framework

Test::Unit

Page 36: Ruby Isn't Just About Rails

class PostTest < Test::Unit::TestCase

def test_simple_slug post = Post.new :title => "First Post" assert_equal "first_post", post.slug end

def test_complex_slug post = Post.new :title => "My Post!") assert_equal "my_post", post.slug end

end

Page 37: Ruby Isn't Just About Rails

Behavior-Driven Development

http://rspec.info

RSpec

Page 38: Ruby Isn't Just About Rails

describe Post do

it "generates a url slug from the title" do post = Post.new :title => "First Post" post.slug.should == "first_post" end

it "drops punctuation from the url slug" do post = Post.new :title => "My Post!" post.slug.should == "my_post" end

end

Page 39: Ruby Isn't Just About Rails

$ rake spec:docPost- generates a url slug from the title- drops punctuation from the url slug

Page 40: Ruby Isn't Just About Rails

Templating Engine

ERB

Page 41: Ruby Isn't Just About Rails

<div class="post"> <h1><%= @post.title %></h1> <div class="body"> <%= @post.body %> </div></div>

Page 42: Ruby Isn't Just About Rails

Templating Engine

ERB

Haml

Page 43: Ruby Isn't Just About Rails

Markup haiku

http://haml.hamptoncatlin.com

Haml

Page 44: Ruby Isn't Just About Rails

.post %h1= @post.title .body= @post.body

Page 45: Ruby Isn't Just About Rails

Ties it all together

http://rack.rubyforge.org

Page 46: Ruby Isn't Just About Rails

The End.

Adam WigginsCodemash 2009

http://adam.blog.heroku.com