Click here to load reader

Ruby over Rails

  • View
    197

  • Download
    0

Embed Size (px)

DESCRIPTION

Ruby has a powerful set of libs and tools that we don't use in our day to day jobs as ruby developers. The main reason for this is because we force logic where it should not be: the template. By refactoring a simple application I'll show you how to unlock the power of Ruby and how to write code that you will love to work with in the future.

Text of Ruby over Rails

  • 1. Ruby over Rails Ruby Day 2014
  • 2. Giuseppe Modarelli Ruby Developer Javascript Developer Drummer gmodarelli gmodarelli gmodarelli.com
  • 3. xml2json
  • 4. Why Ruby over Rails?
  • 5. Your app uses Rails
  • 6. Your app is not Rails
  • 7. Whats Rails?
  • 8. Corey Haines
  • 9. A set of helpers that takes us from a url to a method for both incoming requests and outgoing responses (HTTP) An ORM (DoneRecord) that serves as a database adapter Corey Haines
  • 10. HTTP YOUR APP DB
  • 11. A real life example
  • 12.
    ! !
  • 13.
    ! !
  • 14.
    ! !
  • 15.
    ! !
  • 16.
    ! !
  • 17.
    ! !
  • 18. WHAT THE SHISH!!?!?!?
  • 19.
    ! !
  • 20.
    !
    ! How can we solve this?
  • 21.
    !
    ! Dont start over!
  • 22.
    !
    ! Clean up existing code
  • 23.
    ! !
  • 24.
    !
    ! HAML
  • 25. %div{ id: "dates" } %div{ class: "date #{@contract.signed_at.past? ? 'done' : 'pending'}" } - month = @contract.signed_at.strftime('%B').downcase - day = @contract.signed_at.day.to_s %div{ class: "#{month}" } %div{ class: "#{day}" } %div{ class: "date #{@contract.activation_date.past? ? 'done' : 'pending'}" } - month = @contract.activation_date.strftime('%B').downcase - day = @contract.activation_date.day.to_s %div{ class: "#{month}" } %div{ class: "#{day}" } %div{ class: "date #{@contract.first_invoice_sent_at.past? ? 'done' : 'pending'}" } - month = @contract.first_invoice_sent_at.strftime('%B').downcase - day = @contract.first_invoice_sent_at.day.to_s %div{ class: "#{month}" } %div{ class: "#{day}" }
  • 26. %div{ id: "dates" } %div{ class: "date #{@contract.signed_at.past? ? 'done' : 'pending'} - month = @contract.signed_at.strftime('%B') - day = %div{ class: "#{month} %div %div{ class: "date #{@contract.activation_date.past? ? 'done' : 'pending'} - month = @contract.activation_date.strftime('%B') - day = SLIM %div{ class: "#{month} %div %div{ class: "date #{@contract.first_invoice_sent_at.past? ? 'done' : 'pending'} - month = @contract.first_invoice_sent_at.strftime('%B') - day = %div{ class: "#{month} %div
  • 27. div#dates div class="date #{@contract.signed_at.past? ? 'done' : 'pending'}" - month = @contract.signed_at.strftime('%B').downcase - day = @contract.signed_at.day.to_s div class=month div class=day div class="date #{@contract.activation_date.past? ? 'done' : 'pending'}" - month = @contract.activation_date.strftime('%B').downcase - day = @contract.activation_date.day.to_s div class=month div class=day div class="date #{@contract.first_invoice_sent_at.past? ? 'done' : 'pending'}" - month = @contract.first_invoice_sent_at.strftime('%B').downcase - day = @contract.first_invoice_sent_at.day.to_s div class=month div class=day
  • 28. div#dates div - month = - day = div div div - month = - day = div div div - month = - day = div div SLIM LOGIC-LESS
  • 29. div#dates div - month = - day = div div div - month = - day = Programming by Wishful Thinking div div div - month = - day = div div
  • 30. div#dates - @dates div class="date #{status}" div class=month div class=day
  • 31. div - div Ok cool. But we do need that logic! div div
  • 32. div - div div M V C div
  • 33. div - div div M V C div
  • 34. div - div div M V C div
  • 35. div - div div M V C div
  • 36. div - div div PORO div
  • 37. div#dates - @dates div class="date #{status}" div class=month div class=day
  • 38. describe Presenters::CalendarWidget do let(:date) { DateTime.parse '2014/09/26 08:00:00' } ! describe '#status' do it 'is "done" when the date is in the past' do calendar_widget = described_class.new date expect(calendar_widget.status).to eq('done') end end end
  • 39. class Presenters::CalendarWidget def initialize date end ! def status "done" end end
  • 40. describe Presenters::CalendarWidget do let(:date) { DateTime.parse '2014/09/26 08:00:00' } ! describe '#status' do