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

A Minimalistic Ruby Stack

Francesco Rodríguez
October 21, 2015
50

A Minimalistic Ruby Stack

This presentation shows some simple tools made in Ruby. It was presented at the Oslo Ruby meetup.

Francesco Rodríguez

October 21, 2015
Tweet

Transcript

  1. $ gem list mygem ! mygem (1.0.0, 2.0.0) ! !

    $ ruby -r mygem —e "MyGem::VERSION" 2.0.0
  2. $ ls -a .gs ! $ env | grep GEM

    GEM_HOME=/Code/app/.gs GEM_PATH=/Code/app/.gs: …
  3. $ gs gem install mygem ! $ gem list -i

    mygem false ! $ gs gem list —i mygem true
  4. dep + gs bundler lines of code 189 complexity 197

    Comparison lines of code ~12,000 complexity ~17,000
  5. dep + gs bundler (x86) x xxxxxxxxxx xxxxxxxxxxx xxxxxxxxx xxxxxxxxxx

    xxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxx xxxxxx Complexity
  6. on "posts" do get do res.write("GET /posts") end ! post

    do res.write("POST /posts") end end ! # GET /posts => "GET /posts" # POST /posts => "POST /posts"
  7. on :slug do |slug| get do res.write("GET /#{ slug }")

    end end ! # GET /foo => "GET /foo" # GET /bar => "GET /bar"
  8. on (current_user != nil) do # authenticated routes end !

    on resource.nil? do res.write("404") end
  9. class Users < Tynn end ! Users.define do get do

    # ... end end ! Tynn.define do on "users" do run(Users) end end
  10. • Tynn::Environment • Tynn::JSON • Tynn::NotFound • Tynn::Protection • Tynn::Render

    • Tynn::SecureHeaders • Tynn::Session • Tynn::SSL • Tynn::Static • Tynn::Test
  11. on "articles" do get do json(Article.all) end ! post do

    Article.create(req[:article]) ! res.status = 201 end end Tynn
  12. get "/articles/:id" do article = Article[params[:id]] return status(404) unless article

    article.to_json end ! put "/articles/:id" do article = Article[params[:id]] return status(404) unless article article.update(params[:article]) article.to_json end ! delete "/articles/:id" do article = Article[params[:id]] return status 404 unless article article.delete status 204 end Sinatra
  13. on "articles" do on :id do |id| article = Article[id]

    ! on article.nil? do res.status = 404 end ! get do json(article) end ! put do article.update(req[:article]) json(article) end ! delete do article.delete res.status = 204 end end end Tynn
  14. Framework Requests/sec % from best ==================================================== Rack 10164.77 100.00% Tynn

    9739.69 95.82% Cuba 8714.49 85.73% Lotus (*) 8535.46 83.97% Rails (**) 3175.91 31.24% Sinatra (***) 2890.16 28.43% ! ! (*) Lotus Router (**) Without middlewares, ActionController::Metal (***) Without middlewares. ! https://gist.github.com/frodsan/4cf2b3beab1dee39e2b0
  15. tynn web library hmote template engine ohm / sequel ORM

    scrivener validations posten mailing disc workers