Ruby Isn't Just About Rails

33,112 views

Published on

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

Published in: Technology
0 Comments
20 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
33,112
On SlideShare
0
From Embeds
0
Number of Embeds
337
Actions
Shares
0
Downloads
205
Comments
0
Likes
20
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 http://datamapper.org
  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 http://sequel.rubyforge.org
  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” http://merbivore.org
  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” http://sinatra.rubyforge.org
  27. require 'rubygems' require 'sinatra' require 'lib/posts' post '/posts' post = Post.create! params redirect quot;/posts/#{post.id}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 http://behaviour-driven.org
  32. TATFT Test All The Darn Time
  33. Test Framework Test::Unit
  34. class PostTest < Test::Unit::TestCase def test_simple_slug post = Post.new :title => quot;First Postquot; assert_equal quot;first_postquot;, post.slug end def test_complex_slug post = Post.new :title => quot;My Post!quot;) assert_equal quot;my_postquot;, post.slug end end
  35. RSpec Behavior-Driven Development http://rspec.info
  36. describe Post do it quot;generates a url slug from the titlequot; do post = Post.new :title => quot;First Postquot; post.slug.should == quot;first_postquot; end it quot;drops punctuation from the url slugquot; do post = Post.new :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 http://haml.hamptoncatlin.com
  42. .post %h1= @post.title .body= @post.body
  43. Ties it all together http://rack.rubyforge.org
  44. The End. http://adam.blog.heroku.com Adam Wiggins Codemash 2009

×