Ruby Isn't Just About Rails


Published on

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

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Ruby Isn't Just About Rails

  1. Ruby Isn’t Just About Rails Adam Wiggins Codemash 2009
  2. ?
  3. ? Ruby
  4. You can’t sell a platform
  5. You can’t sell a platform ...without a killer app.
  6. A programming language is a platform
  7. is the killer app Ruby for
  8. Came for Rails, stayed for Ruby
  9. An explosion of Ruby projects in the past 2 years
  10. Let’s take a tour!
  11. Rails is: ORM - ActiveRecord Web Layer - ActionPack Templating - ERB Test Framework - Test::Unit
  12. ORM ActiveRecord
  13. class CreatePosts < ActiveRecord::Migration create_table :posts do |t| t.string :title t.text :body t.datetime :created_at t.integer :post_id end end $ rake db:migrate class Post < ActiveRecord::Base has_many :comments end Post.find(:first, :conditions => [ quot;title = ?quot;, quot;First postquot; ])
  14. ORM ActiveRecord DataMapper Sequel
  15. Define schema in the code instead of the database
  16. class Post include DataMapper::Resource property :id, Serial property :title, String property :body, Text property :created_at, DateTime has n, :comments end DataMapper.auto_upgrade! Post.first(:title => quot;First Postquot;)
  17. Access a database with just hashes - or map models
  18. db = Sequel.connect('mysql://root@localhost/db') db.create_table :posts do primary_key :id varchar :title text :body datetime :created_at end db[:posts].filter(:title => quot;First Postquot;).first
  19. Web Layer ActionPack
  20. ActionController::Routing::Routes.draw do |map| map.resource :posts end class PostsController < ApplicationController def create @post = Post.create! params redirect_to(@post) end def show @post = Post.find(params[:id]) end end
  21. Web Layer ActionPack Merb Sinatra
  22. The hacker’s framework “No code is faster than no code”
  23. Merb::Router.prepare do |router| resource :posts end class Posts < Merb::Controller def create @post = Post.create params redirect(url(:post, @post)) end def show @post = Post.find(params[:id]) display @post end end
  24. use_orm :datamapper use_test :rspec use_template_engine :erb
  25. Merb 2.0 == Rails 3.0
  26. Sinatra The classy microframework for Ruby “Exposed simplicity instead of hidden complexity”
  27. require 'rubygems' require 'sinatra' require 'lib/posts' post '/posts' post = Post.create! params redirect quot;/posts/#{}quot; end get '/posts/:id' do @post = Post.find(params[:id]) erb :post end
  28. Test Framework
  29. Unit tests
  30. TDD Test-Driven Development
  31. BDD Behavior-Driven Development
  32. TATFT Test All The Darn Time
  33. Test Framework Test::Unit
  34. class PostTest < Test::Unit::TestCase def test_simple_slug post = :title => quot;First Postquot; assert_equal quot;first_postquot;, post.slug end def test_complex_slug post = :title => quot;My Post!quot;) assert_equal quot;my_postquot;, post.slug end end
  35. RSpec Behavior-Driven Development
  36. describe Post do it quot;generates a url slug from the titlequot; do post = :title => quot;First Postquot; post.slug.should == quot;first_postquot; end it quot;drops punctuation from the url slugquot; do post = :title => quot;My Post!quot; post.slug.should == quot;my_postquot; end end
  37. $ rake spec:doc Post - generates a url slug from the title - drops punctuation from the url slug
  38. Templating Engine ERB
  39. <div class=quot;postquot;> <h1><%= @post.title %></h1> <div class=quot;bodyquot;> <%= @post.body %> </div> </div>
  40. Templating Engine ERB Haml
  41. Haml Markup haiku
  42. .post %h1= @post.title .body= @post.body
  43. Ties it all together
  44. The End. Adam Wiggins Codemash 2009