Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducción a Cuba

Introducción a Cuba

Workshop given in Ruby Fun Day Argentina 2013

Francesco Rodríguez

November 26, 2013
Tweet

More Decks by Francesco Rodríguez

Other Decks in Programming

Transcript

  1. Mapper simple ! require 'cuba' ! Cuba.define do on '/'

    do res.write 'ᕦ(ò_óˇ)ᕤ' end end ! run Cuba
  2. Mapper simple ! require 'cuba' ! Cuba.define do on '/'

    do res.write 'ᕦ(ò_óˇ)ᕤ' end end ! run Cuba
  3. Mapper simple ! require 'cuba' ! Cuba.define do on '/'

    do res.write 'ᕦ(ò_óˇ)ᕤ' end end ! run Cuba
  4. Mapper simple ! require 'cuba' ! Cuba.define do on '/'

    do res.write 'ᕦ(ò_óˇ)ᕤ' end end ! run Cuba
  5. Mapper simple ! require 'cuba' ! Cuba.define do on '/'

    do res.write 'ᕦ(ò_óˇ)ᕤ' end end ! run Cuba
  6. Mapper simple ! $ rackup config.ru
 …
 * Listening on

    tcp://0.0.0.0:9292 ! $ curl http://localhost:9292/
 ᕦ(ò_óˇ)ᕤ
  7. Matching Rules ! ! Cuba.define do # PATH == /

    on '/' do res.write 'Home' end end
  8. Matching Rules ! ! Cuba.define do on true do #

    on default do res.write 'Home' end end
  9. Matching Rules ! ! Cuba.define do on true do #

    este bloque se ejecuta. res.write 'Home' end ! on false do # este bloque no se ejecuta. res.write 'Never do this at home' end end
  10. Matching Rules ! ! Cuba.define do on true do #

    este bloque se ejecuta. res.write 'Home' end ! on true do # este bloque no se ejecuta. res.write 'Never do this at home' end end
  11. Matching Rules ! ! Cuba.define do on false do #

    este bloque no se ejecuta. res.write 'Meh' end ! on true, false do # este bloque tampoco se ejecuta. res.write 'Meh' end ! on true do # este bloque se ejecuta. res.write 'Finalmente' end end
  12. Parameters ! ! Cuba.define do ! on 'login', param(‘user’), param(‘pass')

    do |user, pass| ! User.authenticate(user, pass) ! end ! end
  13. HTTP Verbs Constraints ! ! Cuba.define do on get do

    end ! on post do end ! on put do end ! on delete do end end
  14. Composition ! ! Cuba.define do on '/gems' do on get,

    root do end ! on new' do end ! on 'status/:status' do |status| end end end
  15. Composition ! ! class Gems < Cuba define do on

    get, root do end ! on 'new' do end ! on 'status/:status' do |status| end end end