Ruby on Rails
Thursday, June 4, 2009
AkitaOnRails.com
           slideshare.net/akitaonrails




Thursday, June 4, 2009
2008
Thursday, June 4, 2009
2008
Thursday, June 4, 2009
13 e 14
                         Outubro

                         2009
Thursday, June 4, 2009
Thursday, June 4, 2009
~108 slides
                          ~90 min


Thursday, June 4, 2009
www.slideshare.net/akitaonrails

                    fabio.akita@locaweb.com.br




Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
“Especialista em
              uma coisa só é um
              amador em todo o
                   resto.”

Thursday, June...
Thursday, June 4, 2009
Ruby on Rails          2.3

                         Ruby   1.8

                Novo Ruby       1.9
Thursday, June 4, 2009
Ruby on Rails          2.3

                         Ruby   1.8

                Novo Ruby       1.9
Thursday, June 4, 2009
Ruby on Rails          2.3

                         Ruby   1.8

                Novo Ruby       1.9
Thursday, June 4, 2009
“Matz”




                         1993
Thursday, June 4, 2009
“Prag Dave”




                         2001
Thursday, June 4, 2009
“DHH”



                          2004
Thursday, June 4, 2009
Charles Nutter



                              2006
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
“Tornar as coisas
               simples fáceis e as
                coisas complexas
                    possíveis”
     ...
Thursday, June 4, 2009
O que dizem
                           por aí ...


Thursday, June 4, 2009
Pouco usado



Thursday, June 4, 2009
Rails não Escala



Thursday, June 4, 2009
Ruby é Lento



Thursday, June 4, 2009
WTF!?

Thursday, June 4, 2009
Pouco usado



Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Rails não Escala



Thursday, June 4, 2009
Thursday, June 4, 2009
Para colocar as coisas em
      perspectiva, o Friendster foi
          escrito em Java e eles
      mudaram para PHP. MyS...
“O The New York Times usou Ruby on Rails para
              agregar, analizar e mostrar os resultados das
            elei...
Ruby é Lento



Thursday, June 4, 2009
x mais lento que C++




Thursday, June 4, 2009
x mais lento que C++
                         0
                             50
                                          ...
Homepage: 331 ms



Thursday, June 4, 2009
Homepage: 331 ms

                         Total: 5.45 s
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
PHP “puro”     331 req/s


                         CakePHP       4 a 8 req/s*


                    Code Igniter      22 ...
PHP “puro”     331 req/s


                         CakePHP       4 a 8 req/s*


                    Code Igniter      22 ...
PHP “puro”     331 req/s


                         CakePHP       4 a 8 req/s*


                    Code Igniter      22 ...
PHP “puro”     331 req/s


                         CakePHP       4 a 8 req/s*


                    Code Igniter      22 ...
Thursday, June 4, 2009
PHP      Reload




                         Java   Persistente




                         Ruby     Misto


Thursday, Ju...
PHP      Reload




                         Java   Persistente




                         Ruby     Misto


Thursday, Ju...
PHP      Reload




                         Java   Persistente




                         Ruby     Misto


Thursday, Ju...
Browser



                            Rails



                          Banco de
                         Banco Slave
  ...
Browser



                           Rails



                         Banco de
                                  Banco S...
Browser



                                     Rails



                         Banco de
                               ...
Browser



                                     Rails



                                              Banco Slave



    ...
Browser



                                     Rails




                         Banco de
                              ...
Browser



                                     Rails



                                Memcached



                    ...
Browser




                                     Rails



                                Memcached



                   ...
Browser



                         Memcached



                                      Rails



                          ...
Browser



                         Memcached             Web Caches



                                      Rails



   ...
Performance
                              !=
                         Escalabilidade

Thursday, June 4, 2009
Performance
                            Ghz
                          “Vertical”

Thursday, June 4, 2009
Escalabilidade
                         MultiCore
                          “Horizontal”

Thursday, June 4, 2009
Ruby on Rails



Thursday, June 4, 2009
RUBY

Thursday, June 4, 2009
Rails          ActiveSupport


                                 RUBY

Thursday, June 4, 2009
ActionController
                         ActionPack
                                               ActionView


         ...
ActiveRecord
                                             ActionController
                         ActionPack
           ...
ActionMailer
                     ActiveRecord
                                             ActionController
             ...
ActiveResource          ActionWebService

                                                   ActionMailer
                ...
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
RSpec
     describe Product do
       include ProductSpecHelper

         before(:each) do
           @product = Product.n...
RSpec
     describe Product do
       include ProductSpecHelper

         before(:each) do
           @product = Product.n...
Model

  class Product < ActiveRecord::Base
    after_create :set_initial_inventory

       has_many :variants, :dependent...
Model

  class Product < ActiveRecord::Base
    after_create :set_initial_inventory

       has_many :variants, :dependent...
Controller

    class UsersController < Spree::BaseController
      resource_controller
      before_filter :initialize_ex...
Controller

    class UsersController < Spree::BaseController
      resource_controller
      before_filter :initialize_ex...
Views ERB
  <div id=quot;product-listingquot;>
    <%= breadcrumbs(@taxon) %>
    <br/>
    <%= render :partial => quot;sh...
Views HAML

      #product-listing
        =breadcrumbs(@taxon)
        %br
        =render :partial => quot;shared/produc...
Rotas RESTFul


  ActionController::Routing::Routes.draw do |map|
    map.connect ':controller/service.wsdl', :action => '...
Rotas RESTFul


  ActionController::Routing::Routes.draw do |map|
                 GET /products/new
    map.connect ':con...
Migrations


        class RenameAppConfiguration < ActiveRecord::Migration
          def self.up
            rename_table...
Migrations


        class RenameAppConfiguration < ActiveRecord::Migration
          def self.up
            rename_table...
“Beautiful Code”



Thursday, June 4, 2009
@Transient
                                                                public BigDecimal getTotal()
      //$Id: Booki...
public int getBeds()
  public void setUser(User user)
                                                                    ...
class Booking < ActiveRecord::Base
               belongs_to :hotel
               belongs_to :user
               validat...
class CreateBookings < ActiveRecord::Migration
                           def self.up
                             create_...
190
                         vs
                         40

Thursday, June 4, 2009
“Eles servem mais de 23 milhões de visitantes/mês. A conversão resultou em
              20 mil linhas de Ruby em vez de 1...
Thursday, June 4, 2009
11 mil
                         classes!

                         46 só de
                         coleções!


Thursday,...
• Classes:
                     • Modules:       • Array
                      • Enumerable    • Hash
                    ...
1.400 Classes:
                                  •
                             classesArray
                     • Module...
Ferramentas
                            Ágeis


Thursday, June 4, 2009
Gerenciamento



Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Repositórios



Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Integração
                          Contínua


Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Manutenção



Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Open Source



Thursday, June 4, 2009
Thursday, June 4, 2009
describe BankAccount do
           before :each do
             @bank_account = BankAccount.new :balance => 250
          ...
Thursday, June 4, 2009
Funcionalidade: Adição
                Para evitar erros bobos
                Como um péssimo matemático
                ...
Before do
   @calc = Calculadora.new
 end

 Dado /que eu digitei (d+) na calculadora/ do |n|
   @calc.push n.to_i
 end

 Q...
class SignupTest < ActionController::IntegrationTest

              def test_trial_account_sign_up
                visit h...
rspec             rspec.info

           cucumber                cukes.info

              shoulda    thoughtbot.com/proje...
• plugins de Active Record
                • plugins de Views
                • plugins de Localização
                • C...
Comunidade



Thursday, June 4, 2009
peepcode.com




                                        Geoffrey
Thursday, June 4, 2009
railsenvy.com




                                         Jason e Gregg
Thursday, June 4, 2009
railscasts.com




                                          Ryan Bates
Thursday, June 4, 2009
guias.rubyonrails.pro.br




                                              Pratik Naik
Thursday, June 4, 2009
rubylearning.org




                                            Satish Talim
Thursday, June 4, 2009
rubyinside.com.br




                                             Peter Cooper
Thursday, June 4, 2009
why.nomedojogo.com




                                          _why
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Thursday, June 4, 2009
Uma pulga ...



Thursday, June 4, 2009
Standish Group - CHAOS Report 2009
Thursday, June 4, 2009
Fracasso Total
             24%


                                                       Sucesso
                         ...
Winston W. Royce - 1970
Thursday, June 4, 2009
“Eu acredito neste conceito mas a
       implementação descrita acima é arriscada
                  e convida falhas.”


 ...
“Eu acredito neste conceito mas a
       implementação descrita acima é arriscada
                  e convida falhas.”


 ...
“Eu acredito neste conceito mas a
       implementação descrita acima é arriscada
                  e convida falhas.”


 ...
Insanidade

Thursday, June 4, 2009
“Querer resultados
              melhores fazendo a
                mesma coisa.”


Thursday, June 4, 2009
“Think Different”




Thursday, June 4, 2009
“Think Different”




Thursday, June 4, 2009
Obrigado!
                          akitaonrails.com




Thursday, June 4, 2009
Upcoming SlideShare
Loading in …5
×

ERECOMPI

1,206 views

Published on

Palestra de Ruby on Rails que dei no evento ERECOMPI, em Teresina, no Piauí.

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

No Downloads
Views
Total views
1,206
On SlideShare
0
From Embeds
0
Number of Embeds
189
Actions
Shares
0
Downloads
64
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

ERECOMPI

  1. 1. Ruby on Rails Thursday, June 4, 2009
  2. 2. AkitaOnRails.com slideshare.net/akitaonrails Thursday, June 4, 2009
  3. 3. 2008 Thursday, June 4, 2009
  4. 4. 2008 Thursday, June 4, 2009
  5. 5. 13 e 14 Outubro 2009 Thursday, June 4, 2009
  6. 6. Thursday, June 4, 2009
  7. 7. ~108 slides ~90 min Thursday, June 4, 2009
  8. 8. www.slideshare.net/akitaonrails fabio.akita@locaweb.com.br Thursday, June 4, 2009
  9. 9. Thursday, June 4, 2009
  10. 10. Thursday, June 4, 2009
  11. 11. Thursday, June 4, 2009
  12. 12. “Especialista em uma coisa só é um amador em todo o resto.” Thursday, June 4, 2009
  13. 13. Thursday, June 4, 2009
  14. 14. Ruby on Rails 2.3 Ruby 1.8 Novo Ruby 1.9 Thursday, June 4, 2009
  15. 15. Ruby on Rails 2.3 Ruby 1.8 Novo Ruby 1.9 Thursday, June 4, 2009
  16. 16. Ruby on Rails 2.3 Ruby 1.8 Novo Ruby 1.9 Thursday, June 4, 2009
  17. 17. “Matz” 1993 Thursday, June 4, 2009
  18. 18. “Prag Dave” 2001 Thursday, June 4, 2009
  19. 19. “DHH” 2004 Thursday, June 4, 2009
  20. 20. Charles Nutter 2006 Thursday, June 4, 2009
  21. 21. Thursday, June 4, 2009
  22. 22. Thursday, June 4, 2009
  23. 23. “Tornar as coisas simples fáceis e as coisas complexas possíveis” Filosofia Ruby Thursday, June 4, 2009
  24. 24. Thursday, June 4, 2009
  25. 25. O que dizem por aí ... Thursday, June 4, 2009
  26. 26. Pouco usado Thursday, June 4, 2009
  27. 27. Rails não Escala Thursday, June 4, 2009
  28. 28. Ruby é Lento Thursday, June 4, 2009
  29. 29. WTF!? Thursday, June 4, 2009
  30. 30. Pouco usado Thursday, June 4, 2009
  31. 31. Thursday, June 4, 2009
  32. 32. Thursday, June 4, 2009
  33. 33. Thursday, June 4, 2009
  34. 34. Thursday, June 4, 2009
  35. 35. Thursday, June 4, 2009
  36. 36. Thursday, June 4, 2009
  37. 37. Thursday, June 4, 2009
  38. 38. Thursday, June 4, 2009
  39. 39. Thursday, June 4, 2009
  40. 40. Thursday, June 4, 2009
  41. 41. Thursday, June 4, 2009
  42. 42. Thursday, June 4, 2009
  43. 43. Thursday, June 4, 2009
  44. 44. Thursday, June 4, 2009
  45. 45. Thursday, June 4, 2009
  46. 46. Thursday, June 4, 2009
  47. 47. Rails não Escala Thursday, June 4, 2009
  48. 48. Thursday, June 4, 2009
  49. 49. 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. Quando as pessoas caem em problemas de escalabilidade, normalmente acham que a linguagem é o problema, mas eu acho que isso raramente é a realidade. Blaine Cook http://www.akitaonrails.com/2008/6/17/chatting-with-blaine-cook-twitter Thursday, June 4, 2009
  50. 50. “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.” http://www.computerworld.com.au/article/268003/ruby_rails_rolls_into_enterprise?fp=16&fpid=1 Thursday, June 4, 2009
  51. 51. Ruby é Lento Thursday, June 4, 2009
  52. 52. x mais lento que C++ Thursday, June 4, 2009
  53. 53. x mais lento que C++ 0 50 100 Python 2 150 Ruby 1.9 200 Perl JRuby Python 3 PHP Ruby 1.8.6 Thursday, June 4, 2009
  54. 54. Homepage: 331 ms Thursday, June 4, 2009
  55. 55. Homepage: 331 ms Total: 5.45 s Thursday, June 4, 2009
  56. 56. Thursday, June 4, 2009
  57. 57. Thursday, June 4, 2009
  58. 58. PHP “puro” 331 req/s CakePHP 4 a 8 req/s* Code Igniter 22 a 98 req/s* Rails (2008) 88 req/s Thursday, June 4, 2009
  59. 59. PHP “puro” 331 req/s CakePHP 4 a 8 req/s* Code Igniter 22 a 98 req/s* Rails (2008) 88 req/s Thursday, June 4, 2009
  60. 60. PHP “puro” 331 req/s CakePHP 4 a 8 req/s* Code Igniter 22 a 98 req/s* Rails (2008) 88 req/s Thursday, June 4, 2009
  61. 61. PHP “puro” 331 req/s CakePHP 4 a 8 req/s* Code Igniter 22 a 98 req/s* Rails (2008) 88 req/s Thursday, June 4, 2009
  62. 62. Thursday, June 4, 2009
  63. 63. PHP Reload Java Persistente Ruby Misto Thursday, June 4, 2009
  64. 64. PHP Reload Java Persistente Ruby Misto Thursday, June 4, 2009
  65. 65. PHP Reload Java Persistente Ruby Misto Thursday, June 4, 2009
  66. 66. Browser Rails Banco de Banco Slave Dados Thursday, June 4, 2009
  67. 67. Browser Rails Banco de Banco Slave Dados Thursday, June 4, 2009
  68. 68. Browser Rails Banco de Banco Slave Dados Thursday, June 4, 2009
  69. 69. Browser Rails Banco Slave Banco de Dados Thursday, June 4, 2009
  70. 70. Browser Rails Banco de Banco Slave Dados Thursday, June 4, 2009
  71. 71. Browser Rails Memcached Banco de Banco Slave Dados Thursday, June 4, 2009
  72. 72. Browser Rails Memcached Banco de Banco Slave Dados Thursday, June 4, 2009
  73. 73. Browser Memcached Rails Memcached Banco de Banco Slave Dados Thursday, June 4, 2009
  74. 74. Browser Memcached Web Caches Rails Memcached Banco de Banco Slave Dados Thursday, June 4, 2009
  75. 75. Performance != Escalabilidade Thursday, June 4, 2009
  76. 76. Performance Ghz “Vertical” Thursday, June 4, 2009
  77. 77. Escalabilidade MultiCore “Horizontal” Thursday, June 4, 2009
  78. 78. Ruby on Rails Thursday, June 4, 2009
  79. 79. RUBY Thursday, June 4, 2009
  80. 80. Rails ActiveSupport RUBY Thursday, June 4, 2009
  81. 81. ActionController ActionPack ActionView Rails ActiveSupport RUBY Thursday, June 4, 2009
  82. 82. ActiveRecord ActionController ActionPack ActionView Rails ActiveSupport RUBY Thursday, June 4, 2009
  83. 83. ActionMailer ActiveRecord ActionController ActionPack ActionView Rails ActiveSupport RUBY Thursday, June 4, 2009
  84. 84. ActiveResource ActionWebService ActionMailer ActiveRecord ActionController ActionPack ActionView Rails ActiveSupport RUBY Thursday, June 4, 2009
  85. 85. Thursday, June 4, 2009
  86. 86. Thursday, June 4, 2009
  87. 87. Thursday, June 4, 2009
  88. 88. Thursday, June 4, 2009
  89. 89. Thursday, June 4, 2009
  90. 90. Thursday, June 4, 2009
  91. 91. Thursday, June 4, 2009
  92. 92. Thursday, June 4, 2009
  93. 93. RSpec describe Product do include ProductSpecHelper before(:each) do @product = Product.new end it quot;should not be valid when emptyquot; do @product.should_not be_valid end it quot;should be valid when having correct informationquot; do @product.attributes = valid_product_attributes @product.should be_valid end end Thursday, June 4, 2009
  94. 94. RSpec describe Product do include ProductSpecHelper before(:each) do @product = Product.new end it quot;should not be valid when emptyquot; do rake spec @product.should_not be_valid end it quot;should be valid when having correct informationquot; do @product.attributes = valid_product_attributes @product.should be_valid end end Thursday, June 4, 2009
  95. 95. Model 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 => :permalink end Thursday, June 4, 2009
  96. 96. Model 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 Product.find(1) belongs_to :tax_category validates_presence_of :name validates_presence_of :master_price validates_presence_of :description make_permalink :with => :name, :field => :permalink end Thursday, June 4, 2009
  97. 97. Controller 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 Thursday, June 4, 2009
  98. 98. Controller class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) /users/1 .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 Thursday, June 4, 2009
  99. 99. Views ERB <div id=quot;product-listingquot;> <%= breadcrumbs(@taxon) %> <br/> <%= render :partial => quot;shared/products.html.erbquot;, :locals => {:products => @products, :taxon => @taxon } %> </div> <% content_for :sidebar do %> <td id=quot;shop-by-colquot; valign=quot;topquot;> <%= render :partial => quot;shared/taxonomiesquot; %> </td> <% end %> <%= render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty? %> Thursday, June 4, 2009
  100. 100. Views HAML #product-listing =breadcrumbs(@taxon) %br =render :partial => quot;shared/products.html.erbquot;, :locals => {:products => @products, :taxon => @taxon} -content_for :sidebar do %td#shop-by-col(:valign => quot;topquot;) =render :partial => quot;shared/taxonomiesquot; =render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty? Thursday, June 4, 2009
  101. 101. Rotas RESTFul ActionController::Routing::Routes.draw do |map| map.connect ':controller/service.wsdl', :action => 'wsdl' map.resources :products, :member => {:change_image => :post} map.resources :addresses map.resources :orders, :has_many => [:line_items] map.namespace :admin do |admin| admin.resources :users admin.resources :products end end Thursday, June 4, 2009
  102. 102. Rotas RESTFul ActionController::Routing::Routes.draw do |map| GET /products/new map.connect ':controller/service.wsdl', :action => 'wsdl' GET /products map.resources :products, :member => POST /products {:change_image => :post} map.resources :addresses GET /products/1 map.resources :orders, GET /products/1/edit :has_many => [:line_items] map.namespacePUT /products/1 :admin do |admin| DESTROY /products/1 admin.resources :users admin.resources :products end end Thursday, June 4, 2009
  103. 103. Migrations 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 end end Thursday, June 4, 2009
  104. 104. Migrations class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end rake db:migrate def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations end end Thursday, June 4, 2009
  105. 105. “Beautiful Code” Thursday, June 4, 2009
  106. 106. @Transient public BigDecimal getTotal() //$Id: Booking.java 5579 2007-06-27 00:06:49Z gavin $ { package org.jboss.seam.example.booking; return hotel.getPrice().multiply( new BigDecimal( getNights() ) ); } import java.io.Serializable; import java.math.BigDecimal; @Transient import java.text.DateFormat; public int getNights() import java.util.Date; { return (int) ( checkoutDate.getTime() - checkinDate.getTime() ) / import javax.persistence.Basic; 1000 / 60 / 60 / 24; import javax.persistence.Entity; } import javax.persistence.GeneratedValue; import javax.persistence.Id; @Id @GeneratedValue import javax.persistence.ManyToOne; public Long getId() import javax.persistence.Temporal; { import javax.persistence.TemporalType; return id; import javax.persistence.Transient; } public void setId(Long id) import org.hibernate.validator.Length; { import org.hibernate.validator.NotNull; this.id = id; import org.hibernate.validator.Pattern; } import org.jboss.seam.annotations.Name; @NotNull @Entity @Basic @Temporal(TemporalType.DATE) @Name(quot;bookingquot;) public Date getCheckinDate() public class Booking implements Serializable { { return checkinDate; private Long id; } private User user; public void setCheckinDate(Date datetime) private Hotel hotel; { private Date checkinDate; this.checkinDate = datetime; private Date checkoutDate; } private String creditCard; private String creditCardName; @ManyToOne @NotNull private int creditCardExpiryMonth; public Hotel getHotel() private int creditCardExpiryYear; { private boolean smoking; return hotel; private int beds; } public void setHotel(Hotel hotel) public Booking() {} { this.hotel = hotel; public Booking(Hotel hotel, User user) } { this.hotel = hotel; @ManyToOne @NotNull this.user = user; public User getUser() } { return user; } Thursday, June 4, 2009
  107. 107. public int getBeds() public void setUser(User user) { { return beds; this.user = user; } } public void setBeds(int beds) @Basic @Temporal(TemporalType.DATE) { @NotNull this.beds = beds; public Date getCheckoutDate() } { @NotNull(message=quot;Credit card name is requiredquot;) return checkoutDate; @Length(min=3, max=70, message=quot;Credit card name is requiredquot;) } public String getCreditCardName() public void setCheckoutDate(Date checkoutDate) { { return creditCardName; this.checkoutDate = checkoutDate; } } public void setCreditCardName(String creditCardName) @NotNull(message=quot;Credit card number is requiredquot;) { @Length(min=16, max=16, message=quot;Credit card number must 16 digits longquot;) this.creditCardName = creditCardName; @Pattern(regex=quot;^d*$quot;, message=quot;Credit card number must be numericquot;) } public String getCreditCard() { public int getCreditCardExpiryMonth() return creditCard; { } return creditCardExpiryMonth; } public void setCreditCard(String creditCard) { public void setCreditCardExpiryMonth(int creditCardExpiryMonth) this.creditCard = creditCard; { } this.creditCardExpiryMonth = creditCardExpiryMonth; } @Transient public String getDescription() public int getCreditCardExpiryYear() { { DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); return creditCardExpiryYear; return hotel==null ? null : hotel.getName() + } quot;, quot; + df.format( getCheckinDate() ) + quot; to quot; + df.format( getCheckoutDate() ); public void setCreditCardExpiryYear(int creditCardExpiryYear) } { this.creditCardExpiryYear = creditCardExpiryYear; public boolean isSmoking() } { return smoking; @Override } public String toString() { public void setSmoking(boolean smoking) return quot;Booking(quot; + user + quot;,quot;+ hotel + quot;)quot;; { } this.smoking = smoking; } } Thursday, June 4, 2009
  108. 108. 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 quot;Booking(#{user},#{hotel})quot; end end Thursday, June 4, 2009
  109. 109. 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 end end Thursday, June 4, 2009
  110. 110. 190 vs 40 Thursday, June 4, 2009
  111. 111. “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. Uma vez completo e otimizado, o site deles agora é mais rápido que antes. Eles também finalizaram a reescrita do sistema em apenas 3 meses com 4 desenvolvedores.” http://www.railsonwave.com/railsonwave/2008/6/4/yellowpages-com-migrates-to-rails Thursday, June 4, 2009
  112. 112. Thursday, June 4, 2009
  113. 113. 11 mil classes! 46 só de coleções! Thursday, June 4, 2009
  114. 114. • Classes: • Modules: • Array • Enumerable • Hash • Comparable • Set • Sorted Set Thursday, June 4, 2009
  115. 115. 1.400 Classes: • classesArray • Modules: • • Enumerable • Hash • Comparable 6 de Set só • • Sorted coleções! Set Thursday, June 4, 2009
  116. 116. Ferramentas Ágeis Thursday, June 4, 2009
  117. 117. Gerenciamento Thursday, June 4, 2009
  118. 118. Thursday, June 4, 2009
  119. 119. Thursday, June 4, 2009
  120. 120. Thursday, June 4, 2009
  121. 121. Repositórios Thursday, June 4, 2009
  122. 122. Thursday, June 4, 2009
  123. 123. Thursday, June 4, 2009
  124. 124. Thursday, June 4, 2009
  125. 125. Thursday, June 4, 2009
  126. 126. Thursday, June 4, 2009
  127. 127. Thursday, June 4, 2009
  128. 128. Integração Contínua Thursday, June 4, 2009
  129. 129. Thursday, June 4, 2009
  130. 130. Thursday, June 4, 2009
  131. 131. Manutenção Thursday, June 4, 2009
  132. 132. Thursday, June 4, 2009
  133. 133. Thursday, June 4, 2009
  134. 134. Thursday, June 4, 2009
  135. 135. Open Source Thursday, June 4, 2009
  136. 136. Thursday, June 4, 2009
  137. 137. describe BankAccount do before :each do @bank_account = BankAccount.new :balance => 250 end it quot;should not be validquot; do @bank_account.should be_valid end it quot;should transfer funds successfullyquot; do @bank_account.should_receive(:transfer) .with_args(:amount => 100) .and_return(true) @bank_account.execute_transaction(:amount => 100) @bank_account.balance.should == 150 end end Thursday, June 4, 2009
  138. 138. Thursday, June 4, 2009
  139. 139. 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 Thursday, June 4, 2009
  140. 140. Before do @calc = Calculadora.new end Dado /que eu digitei (d+) na calculadora/ do |n| @calc.push n.to_i end Quando 'eu aperto o botão de soma' do @result = @calc.soma end Então /o resultado na calculadora deve ser (d*)/ do |result| @result.should == result.to_i end Thursday, June 4, 2009
  141. 141. class SignupTest < ActionController::IntegrationTest def test_trial_account_sign_up visit home_path click_link quot;Sign upquot; fill_in quot;Emailquot;, :with => quot;good@example.comquot; select quot;Free accountquot; click_button quot;Registerquot; end end Thursday, June 4, 2009
  142. 142. rspec rspec.info cucumber cukes.info shoulda thoughtbot.com/projects/shoulda webrat github.com/brynary/webrat integrity integrityapp.com ZenTest zenspider.com Thursday, June 4, 2009
  143. 143. • plugins de Active Record • plugins de Views • plugins de Localização • CMS • Parsers • Autenticadores/Autorizadores Thursday, June 4, 2009
  144. 144. Comunidade Thursday, June 4, 2009
  145. 145. peepcode.com Geoffrey Thursday, June 4, 2009
  146. 146. railsenvy.com Jason e Gregg Thursday, June 4, 2009
  147. 147. railscasts.com Ryan Bates Thursday, June 4, 2009
  148. 148. guias.rubyonrails.pro.br Pratik Naik Thursday, June 4, 2009
  149. 149. rubylearning.org Satish Talim Thursday, June 4, 2009
  150. 150. rubyinside.com.br Peter Cooper Thursday, June 4, 2009
  151. 151. why.nomedojogo.com _why Thursday, June 4, 2009
  152. 152. Thursday, June 4, 2009
  153. 153. Thursday, June 4, 2009
  154. 154. Thursday, June 4, 2009
  155. 155. Thursday, June 4, 2009
  156. 156. Thursday, June 4, 2009
  157. 157. Thursday, June 4, 2009
  158. 158. Uma pulga ... Thursday, June 4, 2009
  159. 159. Standish Group - CHAOS Report 2009 Thursday, June 4, 2009
  160. 160. Fracasso Total 24% Sucesso 32% Fracasso Médio 44% Standish Group - CHAOS Report 2009 Thursday, June 4, 2009
  161. 161. Winston W. Royce - 1970 Thursday, June 4, 2009
  162. 162. “Eu acredito neste conceito mas a implementação descrita acima é arriscada e convida falhas.” Winston W. Royce - 1970 Thursday, June 4, 2009
  163. 163. “Eu acredito neste conceito mas a implementação descrita acima é arriscada e convida falhas.” Winston W. Royce - 1970 Thursday, June 4, 2009
  164. 164. “Eu acredito neste conceito mas a implementação descrita acima é arriscada e convida falhas.” Winston W. Royce - 1970 Thursday, June 4, 2009
  165. 165. Insanidade Thursday, June 4, 2009
  166. 166. “Querer resultados melhores fazendo a mesma coisa.” Thursday, June 4, 2009
  167. 167. “Think Different” Thursday, June 4, 2009
  168. 168. “Think Different” Thursday, June 4, 2009
  169. 169. Obrigado! akitaonrails.com Thursday, June 4, 2009

×