192
Ruby on Rails Friday, August 7, 2009

Oxente on Rails 2009

Embed Size (px)

DESCRIPTION

Mais uma introdução à filosofia das comunidades Ruby e Rails, com ênfase no Ecossistema mais do que na Tecnologia. Vídeo da 37signals: http://www.vimeo.com/6028818Vídeo do Uncle Bob: http://www.vimeo.com/5196176

Citation preview

Page 1: Oxente on Rails 2009

Ruby on RailsFriday, August 7, 2009

Page 2: Oxente on Rails 2009

AkitaOnRails.comslideshare.net/akitaonrails

Friday, August 7, 2009

Page 3: Oxente on Rails 2009

2008Friday, August 7, 2009

Page 4: Oxente on Rails 2009

2008Friday, August 7, 2009

Page 5: Oxente on Rails 2009

13 e 14Outubro

2009Friday, August 7, 2009

Page 6: Oxente on Rails 2009

Friday, August 7, 2009

Page 7: Oxente on Rails 2009

~140 slides~45 min

Friday, August 7, 2009

Page 9: Oxente on Rails 2009

Friday, August 7, 2009

Page 10: Oxente on Rails 2009

Friday, August 7, 2009

Page 11: Oxente on Rails 2009

Friday, August 7, 2009

Page 12: Oxente on Rails 2009

Ruby on Rails 2.3

Ruby 1.8

Novo Ruby 1.9

Friday, August 7, 2009

Page 13: Oxente on Rails 2009

Ruby on Rails 2.3

Ruby 1.8

Novo Ruby 1.9

Friday, August 7, 2009

Page 14: Oxente on Rails 2009

Ruby on Rails 2.3

Ruby 1.8

Novo Ruby 1.9

Friday, August 7, 2009

Page 15: Oxente on Rails 2009

1993

“Matz”

Friday, August 7, 2009

Page 16: Oxente on Rails 2009

Friday, August 7, 2009

Page 17: Oxente on Rails 2009

2001

“Prag Dave”

Friday, August 7, 2009

Page 18: Oxente on Rails 2009

Friday, August 7, 2009

Page 19: Oxente on Rails 2009

2004

“DHH”

Friday, August 7, 2009

Page 20: Oxente on Rails 2009

Friday, August 7, 2009

Page 21: Oxente on Rails 2009

Friday, August 7, 2009

Page 22: Oxente on Rails 2009

2006

Charles Nutter

Friday, August 7, 2009

Page 23: Oxente on Rails 2009

Friday, August 7, 2009

Page 24: Oxente on Rails 2009

Friday, August 7, 2009

Page 25: Oxente on Rails 2009

Friday, August 7, 2009

Page 26: Oxente on Rails 2009

Friday, August 7, 2009

Page 27: Oxente on Rails 2009

“Tornar as coisas

simples fáceis e as

coisas complexas

possíveis”

Filosofia Ruby

Friday, August 7, 2009

Page 28: Oxente on Rails 2009

Friday, August 7, 2009

Page 29: Oxente on Rails 2009

Friday, August 7, 2009

Page 30: Oxente on Rails 2009

Friday, August 7, 2009

Page 31: Oxente on Rails 2009

Friday, August 7, 2009

Page 32: Oxente on Rails 2009

O que dizempor aí ...

Friday, August 7, 2009

Page 33: Oxente on Rails 2009

Pouco usado

Friday, August 7, 2009

Page 34: Oxente on Rails 2009

Rails não Escala

Friday, August 7, 2009

Page 35: Oxente on Rails 2009

Ruby é Lento

Friday, August 7, 2009

Page 36: Oxente on Rails 2009

WTF!?

Friday, August 7, 2009

Page 37: Oxente on Rails 2009

Pouco usado

Friday, August 7, 2009

Page 38: Oxente on Rails 2009

Friday, August 7, 2009

Page 39: Oxente on Rails 2009

Friday, August 7, 2009

Page 40: Oxente on Rails 2009

Friday, August 7, 2009

Page 41: Oxente on Rails 2009

Friday, August 7, 2009

Page 42: Oxente on Rails 2009

Friday, August 7, 2009

Page 43: Oxente on Rails 2009

Friday, August 7, 2009

Page 44: Oxente on Rails 2009

Friday, August 7, 2009

Page 45: Oxente on Rails 2009

Friday, August 7, 2009

Page 46: Oxente on Rails 2009

Friday, August 7, 2009

Page 47: Oxente on Rails 2009

Friday, August 7, 2009

Page 48: Oxente on Rails 2009

Friday, August 7, 2009

Page 49: Oxente on Rails 2009

Rails não Escala

Friday, August 7, 2009

Page 50: Oxente on Rails 2009

Friday, August 7, 2009

Page 52: Oxente on Rails 2009

Para colocar as coisas em perspectiva, o Friendster foi

escrito em Java e eles mudaram para PHP. MySpace foi escrito em ColdFusion e eles mudaram para ASP.NET.

Blaine Cook

http://www.akitaonrails.com/2008/6/17/chatting-with-blaine-cook-twitter

Friday, August 7, 2009

Page 53: Oxente on Rails 2009

Para colocar as coisas em perspectiva, o Friendster foi

escrito em Java e eles mudaram para PHP. MySpace foi escrito em ColdFusion e eles mudaram para ASP.NET.

Blaine Cook

http://www.akitaonrails.com/2008/6/17/chatting-with-blaine-cook-twitter

Quando as pessoas caem em problemas de escalabilidade, normalmente acham que a

linguagem é o problema, mas eu acho que isso raramente

é a realidade.

Friday, August 7, 2009

Page 54: Oxente on Rails 2009

http://www.computerworld.com.au/article/268003/ruby_rails_rolls_into_enterprise?fp=16&fpid=1

“O The New York Times usou Ruby on Rails para agregar, analizar e mostrar os resultados das

eleições em quase tempo real em um de seus sites mais acessados de todos os tempos.”

Friday, August 7, 2009

Page 55: Oxente on Rails 2009

http://www.computerworld.com.au/article/268003/ruby_rails_rolls_into_enterprise?fp=16&fpid=1

“O The New York Times usou Ruby on Rails para agregar, analizar e mostrar os resultados das

eleições em quase tempo real em um de seus sites mais acessados de todos os tempos.”

Friday, August 7, 2009

Page 56: Oxente on Rails 2009

Ruby é Lento

Friday, August 7, 2009

Page 57: Oxente on Rails 2009

x mais lento que C++

Friday, August 7, 2009

Page 58: Oxente on Rails 2009

0

50

100

150

200

Python 2

Ruby 1.9

Perl

JRuby

Python 3

PHP

Ruby 1.8.6

x mais lento que C++

Friday, August 7, 2009

Page 59: Oxente on Rails 2009

Homepage: 331 ms

Friday, August 7, 2009

Page 60: Oxente on Rails 2009

Homepage: 331 ms

Total: 5.45 s

Friday, August 7, 2009

Page 61: Oxente on Rails 2009

Friday, August 7, 2009

Page 62: Oxente on Rails 2009

Performance

!=Escalabilidade

Friday, August 7, 2009

Page 63: Oxente on Rails 2009

Ruby on Rails

Friday, August 7, 2009

Page 64: Oxente on Rails 2009

Friday, August 7, 2009

Page 65: Oxente on Rails 2009

Código que gera Código

Convention over Configuration

Don’t Repeat Yourself

Extreme Programming

Friday, August 7, 2009

Page 66: Oxente on Rails 2009

Código que gera Código

Convention over Configuration

Don’t Repeat Yourself

Extreme Programming

Friday, August 7, 2009

Page 67: Oxente on Rails 2009

Código que gera Código

Convention over Configuration

Don’t Repeat Yourself

Extreme Programming

Friday, August 7, 2009

Page 68: Oxente on Rails 2009

Código que gera Código

Convention over Configuration

Don’t Repeat Yourself

Extreme Programming

Friday, August 7, 2009

Page 69: Oxente on Rails 2009

Friday, August 7, 2009

Page 70: Oxente on Rails 2009

Friday, August 7, 2009

Page 71: Oxente on Rails 2009

Friday, August 7, 2009

Page 72: Oxente on Rails 2009

Friday, August 7, 2009

Page 73: Oxente on Rails 2009

Friday, August 7, 2009

Page 74: Oxente on Rails 2009

Friday, August 7, 2009

Page 75: Oxente on Rails 2009

Friday, August 7, 2009

Page 76: Oxente on Rails 2009

Friday, August 7, 2009

Page 77: Oxente on Rails 2009

Friday, August 7, 2009

Page 78: Oxente on Rails 2009

Friday, August 7, 2009

Page 79: Oxente on Rails 2009

Friday, August 7, 2009

Page 80: Oxente on Rails 2009

Friday, August 7, 2009

Page 81: Oxente on Rails 2009

Friday, August 7, 2009

Page 82: Oxente on Rails 2009

Friday, August 7, 2009

Page 83: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 84: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 85: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 86: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 87: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 88: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 89: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 90: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Friday, August 7, 2009

Page 91: Oxente on Rails 2009

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Product.find(1)

Friday, August 7, 2009

Page 92: Oxente on Rails 2009

<div id="product-listing"> <%= breadcrumbs(@taxon) %> <br/> <%= render :partial => "shared/products.html.erb", :locals => {:products => @products, :taxon => @taxon } %></div>

<% content_for :sidebar do %> <td id="shop-by-col" valign="top"> <%= render :partial => "shared/taxonomies" %> </td><% end %>

<%= render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty? %>

Views ERB

Friday, August 7, 2009

Page 93: Oxente on Rails 2009

<div id="product-listing"> <%= breadcrumbs(@taxon) %> <br/> <%= render :partial => "shared/products.html.erb", :locals => {:products => @products, :taxon => @taxon } %></div>

<% content_for :sidebar do %> <td id="shop-by-col" valign="top"> <%= render :partial => "shared/taxonomies" %> </td><% end %>

<%= render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty? %>

Views ERB

Friday, August 7, 2009

Page 94: Oxente on Rails 2009

<div id="product-listing"> <%= breadcrumbs(@taxon) %> <br/> <%= render :partial => "shared/products.html.erb", :locals => {:products => @products, :taxon => @taxon } %></div>

<% content_for :sidebar do %> <td id="shop-by-col" valign="top"> <%= render :partial => "shared/taxonomies" %> </td><% end %>

<%= render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty? %>

Views ERB

Friday, August 7, 2009

Page 95: Oxente on Rails 2009

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

map.resources :products map.resources :addresses map.resources :orders, :has_many => [:line_items]

map.namespace :admin do |admin| admin.resources :users admin.resources :products endend

Rotas RESTFul

Friday, August 7, 2009

Page 96: Oxente on Rails 2009

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

map.resources :products map.resources :addresses map.resources :orders, :has_many => [:line_items]

map.namespace :admin do |admin| admin.resources :users admin.resources :products endend

Rotas RESTFul

Friday, August 7, 2009

Page 97: Oxente on Rails 2009

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

map.resources :products map.resources :addresses map.resources :orders, :has_many => [:line_items]

map.namespace :admin do |admin| admin.resources :users admin.resources :products endend

Rotas RESTFul

Friday, August 7, 2009

Page 98: Oxente on Rails 2009

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

map.resources :products map.resources :addresses map.resources :orders, :has_many => [:line_items]

map.namespace :admin do |admin| admin.resources :users admin.resources :products endend

Rotas RESTFul

Friday, August 7, 2009

Page 99: Oxente on Rails 2009

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

map.resources :products map.resources :addresses map.resources :orders, :has_many => [:line_items]

map.namespace :admin do |admin| admin.resources :users admin.resources :products endend

Rotas RESTFul

GET /products/newGET /productsPOST /productsGET /products/1GET /products/1/editPUT /products/1DESTROY /products/1

Friday, August 7, 2009

Page 100: Oxente on Rails 2009

class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end

create.after { self.current_user = @user }

create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end

Controller

Friday, August 7, 2009

Page 101: Oxente on Rails 2009

class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end

create.after { self.current_user = @user }

create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end

Controller

Friday, August 7, 2009

Page 102: Oxente on Rails 2009

class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end

create.after { self.current_user = @user }

create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end

Controller

Friday, August 7, 2009

Page 103: Oxente on Rails 2009

class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end

create.after { self.current_user = @user }

create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end

Controller

Friday, August 7, 2009

Page 104: Oxente on Rails 2009

class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end

create.after { self.current_user = @user }

create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end

Controller

/users/1

Friday, August 7, 2009

Page 105: Oxente on Rails 2009

class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end

def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations endend

Migrations

Friday, August 7, 2009

Page 106: Oxente on Rails 2009

class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end

def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations endend

Migrations

Friday, August 7, 2009

Page 107: Oxente on Rails 2009

class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end

def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations endend

Migrations

Friday, August 7, 2009

Page 108: Oxente on Rails 2009

class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end

def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations endend

Migrations

Friday, August 7, 2009

Page 109: Oxente on Rails 2009

class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end

def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations endend

Migrations

rake db:migrate

Friday, August 7, 2009

Page 110: Oxente on Rails 2009

Open Source

Friday, August 7, 2009

Page 111: Oxente on Rails 2009

Friday, August 7, 2009

Page 112: Oxente on Rails 2009

describe BankAccount do before :each do @bank_account = BankAccount.new :balance => 250 end it "should not be valid" do @bank_account.should be_valid end it "should transfer funds successfully" do @bank_account.should_receive(:transfer) .with_args(:amount => 100) .and_return(true) @bank_account.execute_transaction(:amount => 100) @bank_account.balance.should == 150 endend

Friday, August 7, 2009

Page 113: Oxente on Rails 2009

describe BankAccount do before :each do @bank_account = BankAccount.new :balance => 250 end it "should not be valid" do @bank_account.should be_valid end it "should transfer funds successfully" do @bank_account.should_receive(:transfer) .with_args(:amount => 100) .and_return(true) @bank_account.execute_transaction(:amount => 100) @bank_account.balance.should == 150 endend

Friday, August 7, 2009

Page 114: Oxente on Rails 2009

describe BankAccount do before :each do @bank_account = BankAccount.new :balance => 250 end it "should not be valid" do @bank_account.should be_valid end it "should transfer funds successfully" do @bank_account.should_receive(:transfer) .with_args(:amount => 100) .and_return(true) @bank_account.execute_transaction(:amount => 100) @bank_account.balance.should == 150 endend

Friday, August 7, 2009

Page 115: Oxente on Rails 2009

describe BankAccount do before :each do @bank_account = BankAccount.new :balance => 250 end it "should not be valid" do @bank_account.should be_valid end it "should transfer funds successfully" do @bank_account.should_receive(:transfer) .with_args(:amount => 100) .and_return(true) @bank_account.execute_transaction(:amount => 100) @bank_account.balance.should == 150 endend

Friday, August 7, 2009

Page 116: Oxente on Rails 2009

Friday, August 7, 2009

Page 117: Oxente on Rails 2009

Funcionalidade: Adição Para evitar erros bobos Como um péssimo matemático Eu quero saber como somar dois números Cenário: Adicionar dois números Dado que eu digitei 50 na calculadora E que eu digitei 70 na calculadora Quando eu aperto o botão de soma Então o resultado na calculadora deve ser 120

Friday, August 7, 2009

Page 118: Oxente on Rails 2009

Funcionalidade: Adição Para evitar erros bobos Como um péssimo matemático Eu quero saber como somar dois números Cenário: Adicionar dois números Dado que eu digitei 50 na calculadora E que eu digitei 70 na calculadora Quando eu aperto o botão de soma Então o resultado na calculadora deve ser 120

Friday, August 7, 2009

Page 119: Oxente on Rails 2009

Before do @calc = Calculadora.newend Dado /que eu digitei (\d+) na calculadora/ do |n| @calc.push n.to_iend Quando 'eu aperto o botão de soma' do @result = @calc.somaend Então /o resultado na calculadora deve ser (\d*)/ do |result| @result.should == result.to_iend

Friday, August 7, 2009

Page 120: Oxente on Rails 2009

Before do @calc = Calculadora.newend Dado /que eu digitei (\d+) na calculadora/ do |n| @calc.push n.to_iend Quando 'eu aperto o botão de soma' do @result = @calc.somaend Então /o resultado na calculadora deve ser (\d*)/ do |result| @result.should == result.to_iend

Friday, August 7, 2009

Page 121: Oxente on Rails 2009

Before do @calc = Calculadora.newend Dado /que eu digitei (\d+) na calculadora/ do |n| @calc.push n.to_iend Quando 'eu aperto o botão de soma' do @result = @calc.somaend Então /o resultado na calculadora deve ser (\d*)/ do |result| @result.should == result.to_iend

Friday, August 7, 2009

Page 122: Oxente on Rails 2009

Before do @calc = Calculadora.newend Dado /que eu digitei (\d+) na calculadora/ do |n| @calc.push n.to_iend Quando 'eu aperto o botão de soma' do @result = @calc.somaend Então /o resultado na calculadora deve ser (\d*)/ do |result| @result.should == result.to_iend

Friday, August 7, 2009

Page 123: Oxente on Rails 2009

class SignupTest < ActionController::IntegrationTest

def test_trial_account_sign_up visit home_path click_link "Sign up" fill_in "Email", :with => "[email protected]" select "Free account" click_button "Register" end

end

Friday, August 7, 2009

Page 124: Oxente on Rails 2009

Friday, August 7, 2009

Page 125: Oxente on Rails 2009

rspec rspec.info

cucumber cukes.info

shoulda thoughtbot.com/projects/shoulda

webrat github.com/brynary/webrat

integrity integrityapp.com

ZenTest zenspider.com

Friday, August 7, 2009

Page 126: Oxente on Rails 2009

• plugins de Active Record

• plugins de Views

• plugins de Localização

• CMS

• Parsers

• Autenticadores/Autorizadores

Friday, August 7, 2009

Page 127: Oxente on Rails 2009

“Beautiful Code”

Friday, August 7, 2009

Page 128: Oxente on Rails 2009

//$Id: Booking.java 5579 2007-06-27 00:06:49Z gavin $package org.jboss.seam.example.booking;

import java.io.Serializable;import java.math.BigDecimal;import java.text.DateFormat;import java.util.Date;

import javax.persistence.Basic;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.ManyToOne;import javax.persistence.Temporal;import javax.persistence.TemporalType;import javax.persistence.Transient;

import org.hibernate.validator.Length;import org.hibernate.validator.NotNull;import org.hibernate.validator.Pattern;import org.jboss.seam.annotations.Name;

@Entity@Name("booking")public class Booking implements Serializable{ private Long id; private User user; private Hotel hotel; private Date checkinDate; private Date checkoutDate; private String creditCard; private String creditCardName; private int creditCardExpiryMonth; private int creditCardExpiryYear; private boolean smoking; private int beds; public Booking() {} public Booking(Hotel hotel, User user) { this.hotel = hotel; this.user = user; }

@Transient public BigDecimal getTotal() { return hotel.getPrice().multiply( new BigDecimal( getNights() ) ); }

@Transient public int getNights() { return (int) ( checkoutDate.getTime() - checkinDate.getTime() ) / 1000 / 60 / 60 / 24; }

@Id @GeneratedValue public Long getId() { return id; } public void setId(Long id) { this.id = id; } @NotNull @Basic @Temporal(TemporalType.DATE) public Date getCheckinDate() { return checkinDate; } public void setCheckinDate(Date datetime) { this.checkinDate = datetime; }

@ManyToOne @NotNull public Hotel getHotel() { return hotel; } public void setHotel(Hotel hotel) { this.hotel = hotel; } @ManyToOne @NotNull public User getUser() { return user; }

Friday, August 7, 2009

Page 129: Oxente on Rails 2009

public void setUser(User user) { this.user = user; } @Basic @Temporal(TemporalType.DATE) @NotNull public Date getCheckoutDate() { return checkoutDate; } public void setCheckoutDate(Date checkoutDate) { this.checkoutDate = checkoutDate; } @NotNull(message="Credit card number is required") @Length(min=16, max=16, message="Credit card number must 16 digits long") @Pattern(regex="^\\d*$", message="Credit card number must be numeric") public String getCreditCard() { return creditCard; }

public void setCreditCard(String creditCard) { this.creditCard = creditCard; } @Transient public String getDescription() { DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); return hotel==null ? null : hotel.getName() + ", " + df.format( getCheckinDate() ) + " to " + df.format( getCheckoutDate() ); }

public boolean isSmoking() { return smoking; }

public void setSmoking(boolean smoking) { this.smoking = smoking; }

public int getBeds() { return beds; }

public void setBeds(int beds) { this.beds = beds; } @NotNull(message="Credit card name is required") @Length(min=3, max=70, message="Credit card name is required") public String getCreditCardName() { return creditCardName; }

public void setCreditCardName(String creditCardName) { this.creditCardName = creditCardName; }

public int getCreditCardExpiryMonth() { return creditCardExpiryMonth; }

public void setCreditCardExpiryMonth(int creditCardExpiryMonth) { this.creditCardExpiryMonth = creditCardExpiryMonth; }

public int getCreditCardExpiryYear() { return creditCardExpiryYear; }

public void setCreditCardExpiryYear(int creditCardExpiryYear) { this.creditCardExpiryYear = creditCardExpiryYear; } @Override public String toString() { return "Booking(" + user + ","+ hotel + ")"; }

}

Friday, August 7, 2009

Page 130: Oxente on Rails 2009

class Booking < ActiveRecord::Base belongs_to :hotel belongs_to :user validates_presence_of :hotel validates_presence_of :user validates_presence_of :credit_card validates_presence_of :credit_card_name validates_length_of :credit_card, :within => 16..16 validates_format_of :credit_card, :with => /^\\d*$/ validates_length_of :credit_card_name, :within => 3..70 def total hotel.price * nights end def nights ((checkout_date - checkin_date) / 1.day).round end def to_s "Booking(#{user},#{hotel})" endend

Friday, August 7, 2009

Page 131: Oxente on Rails 2009

class Booking < ActiveRecord::Base belongs_to :hotel belongs_to :user validates_presence_of :hotel validates_presence_of :user validates_presence_of :credit_card validates_presence_of :credit_card_name validates_length_of :credit_card, :within => 16..16 validates_format_of :credit_card, :with => /^\\d*$/ validates_length_of :credit_card_name, :within => 3..70 def total hotel.price * nights end def nights ((checkout_date - checkin_date) / 1.day).round end def to_s "Booking(#{user},#{hotel})" endend

Friday, August 7, 2009

Page 132: Oxente on Rails 2009

class CreateBookings < ActiveRecord::Migration def self.up create_table :bookings do |t| t.references :user t.references :hotel t.datetime :checkin t.datetime :checkout t.string :credit_card t.string :credit_card_name t.integer :credit_card_expiry_month t.integer :credit_card_expiry_year t.boolean :smoking t.integer :beds

t.timestamps end end

def self.down drop_table :bookings endend

Friday, August 7, 2009

Page 133: Oxente on Rails 2009

class CreateBookings < ActiveRecord::Migration def self.up create_table :bookings do |t| t.references :user t.references :hotel t.datetime :checkin t.datetime :checkout t.string :credit_card t.string :credit_card_name t.integer :credit_card_expiry_month t.integer :credit_card_expiry_year t.boolean :smoking t.integer :beds

t.timestamps end end

def self.down drop_table :bookings endend

Friday, August 7, 2009

Page 134: Oxente on Rails 2009

class CreateBookings < ActiveRecord::Migration def self.up create_table :bookings do |t| t.references :user t.references :hotel t.datetime :checkin t.datetime :checkout t.string :credit_card t.string :credit_card_name t.integer :credit_card_expiry_month t.integer :credit_card_expiry_year t.boolean :smoking t.integer :beds

t.timestamps end end

def self.down drop_table :bookings endend

Friday, August 7, 2009

Page 135: Oxente on Rails 2009

190vs

40

Friday, August 7, 2009

Page 136: Oxente on Rails 2009

http://www.railsonwave.com/railsonwave/2008/6/4/yellowpages-com-migrates-to-rails

“Eles servem mais de 23 milhões de visitantes/mês. A conversão resultou em 20 mil linhas de Ruby em vez de 125 mil linhas de Java e, mais importante,

facilitou a dificuldade que tinham em manutenção. Eles também finalizaram a reescrita do sistema em apenas 3 meses com 4 desenvolvedores. Uma vez completo e otimizado, o site deles agora é mais rápido que antes.”

Friday, August 7, 2009

Page 137: Oxente on Rails 2009

http://www.railsonwave.com/railsonwave/2008/6/4/yellowpages-com-migrates-to-rails

“Eles servem mais de 23 milhões de visitantes/mês. A conversão resultou em 20 mil linhas de Ruby em vez de 125 mil linhas de Java e, mais importante,

facilitou a dificuldade que tinham em manutenção. Eles também finalizaram a reescrita do sistema em apenas 3 meses com 4 desenvolvedores. Uma vez completo e otimizado, o site deles agora é mais rápido que antes.”

Friday, August 7, 2009

Page 138: Oxente on Rails 2009

http://www.railsonwave.com/railsonwave/2008/6/4/yellowpages-com-migrates-to-rails

“Eles servem mais de 23 milhões de visitantes/mês. A conversão resultou em 20 mil linhas de Ruby em vez de 125 mil linhas de Java e, mais importante,

facilitou a dificuldade que tinham em manutenção. Eles também finalizaram a reescrita do sistema em apenas 3 meses com 4 desenvolvedores. Uma vez completo e otimizado, o site deles agora é mais rápido que antes.”

Friday, August 7, 2009

Page 139: Oxente on Rails 2009

http://www.railsonwave.com/railsonwave/2008/6/4/yellowpages-com-migrates-to-rails

“Eles servem mais de 23 milhões de visitantes/mês. A conversão resultou em 20 mil linhas de Ruby em vez de 125 mil linhas de Java e, mais importante,

facilitou a dificuldade que tinham em manutenção. Eles também finalizaram a reescrita do sistema em apenas 3 meses com 4 desenvolvedores. Uma vez completo e otimizado, o site deles agora é mais rápido que antes.”

Friday, August 7, 2009

Page 140: Oxente on Rails 2009

Friday, August 7, 2009

Page 141: Oxente on Rails 2009

11 mil

classes!

46 só de

coleções!

Friday, August 7, 2009

Page 142: Oxente on Rails 2009

• Modules:

• Enumerable

• Comparable

• Classes:

• Array

• Hash

• Set

• Sorted Set

Friday, August 7, 2009

Page 143: Oxente on Rails 2009

• Modules:

• Enumerable

• Comparable

• Classes:

• Array

• Hash

• Set

• Sorted Set

1.400

classes

só 6 de

coleções!

Friday, August 7, 2009

Page 144: Oxente on Rails 2009

Mitos?

Friday, August 7, 2009

Page 145: Oxente on Rails 2009

Friday, August 7, 2009

Page 146: Oxente on Rails 2009

Mais Produtivo

“Melhor”

Anti-legado

Friday, August 7, 2009

Page 147: Oxente on Rails 2009

Mais Produtivo

“Melhor”

Anti-legado

Friday, August 7, 2009

Page 148: Oxente on Rails 2009

Mais Produtivo

“Melhor”

Anti-legado

Friday, August 7, 2009

Page 149: Oxente on Rails 2009

Agilidade

Friday, August 7, 2009

Page 150: Oxente on Rails 2009

Friday, August 7, 2009

Page 151: Oxente on Rails 2009

Robert C. Martin

Friday, August 7, 2009

Page 152: Oxente on Rails 2009

“Uncle Bob”

Friday, August 7, 2009

Page 153: Oxente on Rails 2009

Código Limpo

Friday, August 7, 2009

Page 154: Oxente on Rails 2009

Friday, August 7, 2009

Page 155: Oxente on Rails 2009

Test Driven Development

Friday, August 7, 2009

Page 156: Oxente on Rails 2009

Friday, August 7, 2009

Page 157: Oxente on Rails 2009

Ferramentas Ágeis

Friday, August 7, 2009

Page 158: Oxente on Rails 2009

Gerenciamento

Friday, August 7, 2009

Page 159: Oxente on Rails 2009

Friday, August 7, 2009

Page 160: Oxente on Rails 2009

Friday, August 7, 2009

Page 161: Oxente on Rails 2009

Friday, August 7, 2009

Page 162: Oxente on Rails 2009

Repositórios

Friday, August 7, 2009

Page 163: Oxente on Rails 2009

Friday, August 7, 2009

Page 164: Oxente on Rails 2009

Friday, August 7, 2009

Page 165: Oxente on Rails 2009

Integração Contínua

Friday, August 7, 2009

Page 166: Oxente on Rails 2009

Friday, August 7, 2009

Page 167: Oxente on Rails 2009

Friday, August 7, 2009

Page 168: Oxente on Rails 2009

Friday, August 7, 2009

Page 169: Oxente on Rails 2009

Deployment

Friday, August 7, 2009

Page 170: Oxente on Rails 2009

Friday, August 7, 2009

Page 171: Oxente on Rails 2009

Friday, August 7, 2009

Page 172: Oxente on Rails 2009

Friday, August 7, 2009

Page 173: Oxente on Rails 2009

Monitoramento

Friday, August 7, 2009

Page 174: Oxente on Rails 2009

Friday, August 7, 2009

Page 175: Oxente on Rails 2009

Friday, August 7, 2009

Page 176: Oxente on Rails 2009

Friday, August 7, 2009

Page 177: Oxente on Rails 2009

Comunidade

Friday, August 7, 2009

Page 178: Oxente on Rails 2009

Geoffrey

peepcode.com

Friday, August 7, 2009

Page 179: Oxente on Rails 2009

Jason e Gregg

railsenvy.com

Friday, August 7, 2009

Page 180: Oxente on Rails 2009

Ryan Bates

railscasts.com

Friday, August 7, 2009

Page 181: Oxente on Rails 2009

Pratik Naik

guias.rubyonrails.pro.br

Friday, August 7, 2009

Page 182: Oxente on Rails 2009

Satish Talim

rubylearning.org

Friday, August 7, 2009

Page 183: Oxente on Rails 2009

Peter Cooper

rubyinside.com.br

Friday, August 7, 2009

Page 184: Oxente on Rails 2009

_why

why.nomedojogo.com

Friday, August 7, 2009

Page 185: Oxente on Rails 2009

Friday, August 7, 2009

Page 186: Oxente on Rails 2009

Friday, August 7, 2009

Page 187: Oxente on Rails 2009

Friday, August 7, 2009

Page 188: Oxente on Rails 2009

Friday, August 7, 2009

Page 189: Oxente on Rails 2009

Friday, August 7, 2009

Page 190: Oxente on Rails 2009

Friday, August 7, 2009

Page 191: Oxente on Rails 2009

Friday, August 7, 2009

Page 192: Oxente on Rails 2009

Obrigado!akitaonrails.com

Friday, August 7, 2009