SlideShare a Scribd company logo
1 of 32
Rack is Spectacular
Learning Rack by making a cheap Rails knockoff
WARNING
CODE HEAVY
  HTTP
  Ruby
  Rails
WARNING
   CODE HEAVY

 So get the code
http://bit.ly/spectac

        c9c340bb
WARNING
 CODE HEAVY
 NOT READY
    FOR
PRODUCTION
    c9c340bb
Rack

• Standard Ruby-HTTP interface
• Write (framework) once
• Run anywhere (that is Rack-compatible)
• Rails, Sinatra, Camping
• Mongrel, Passenger, Unicorn
A Rack Application
                                  config.ru
  use Rack::ContentLength
   
  run(proc do
    [ 200, { 'Content-type' => 'text/plain'}, 'hello world']
  end)



Response Code
                         Response Headers
                                                               Response Body

                                 c9c340bb
What is Rails

• ActionPack
 • Router - maps URLs to code
 • Controller - environment for code
 • View - generating response body
• ActiveRecord - database access
The Essential Rails

• ActionPack
 • Router - maps URLs to code
 • Controller - environment for code
 • View - generating response body
• ActiveRecord - database access
config.ru
              require 'lib/spectacular.rb'
              use Rack::ContentLength
               
              run(Spectacular::App.new)


                          lib/spectacular/app.rb
module Spectacular
  class App
    def call(environment)
      [ 200, { 'Content-type' => 'text/plain'}, 'hello world']
    end
  end
end


                                   0fad6a02
lib/spectacular/app.rb

module Spectacular
  class App
…
    def call(environment)
      method = environment['REQUEST_METHOD']
      path = environment['PATH_INFO']
      @dispatcher.dispatch method, path, environment
    rescue => exception
      error_backtrace exception, environment
    end
 
    private
    def error_backtrace(exception, environment)
      exception_info = “some html” 
      [500, { 'Content-type' => 'text/html'}, exception_info]
    end
…
  end
end




                             2a0d1445
lib/spectacular/app.rb

module Spectacular
  class App
…
    def call(environment)
              breaks; no dispatcher yet
      method = environment['REQUEST_METHOD']
      path = environment['PATH_INFO']
      @dispatcher.dispatch method, path, environment
    rescue => exception
      error_backtrace exception, environment
    end
 
    private
    def error_backtrace(exception, environment)
      exception_info = “some html” 
      [500, { 'Content-type' => 'text/html'}, exception_info]
    end
…
  end
end




                             2a0d1445
Dispatch & Routing are
the most complicated
 parts of Rails
              [citation needed]
But That’s Okay

• We’re not building Rails
• It’s okay if we Fail to Scale
• Just use an array to map paths to
  controllers and actions
lib/spectacular/dispatcher.rb
    def get_route(path)
      @routes.detect{ |r| path === r[0] }
    end
…
    class RoutePen
      def route(path, controller, method)
        @routes << [path, controller, method]
      end
    end




                      9cfb9609
lib/spectacular/controller.rb
    def response_for(method)
      @method = method
      send @method
      [response_code, headers, body]
    end
…
    def template_file
      File.join(APP_DIR, 'views', controller_name, "#{@method}.html.haml")
    end
…
    def body
      return @body if defined? @body
      template = File.read template_file
      engine = Haml::Engine.new template
      @body = engine.render
    end




                                           ce2f00a3
app/controllers/hello_controller.rb
class HelloController < Spectacular::Controller
  def index
  end
end




       app/views/hello/index.html.haml
                       hello world




                       ce2f00a3
Wildcards
          lib/spectacular/dispatcher.rb

def get_route(path)
 @routes.detect{ |r| r[0] === path }
end




                   48b08205
===
0 :> /abc/ === 'abc'
   # => true
0 :> String === 'abc'
   # => true
0 :> /too+t/ === 'toooooooooot'
   # => true
A Wildcard Route

                app/routes.rb
route /too+t/, TootController, :toot




                  48b08205
Using the Path
    app/controllers/toot_controller.rb
class TootController < Spectacular::Controller
 def toot
   @toot = @path.gsub('/','')
 end
end



       app/views/toot/toot.html.haml

             %h1=@toot
                     48b08205
404


• When we can’t figure out how to process a
  request, that should be a “404”
• We can simply make a wildcard route
app/routes.rb
route //, ErrorController, :not_found



       app/controllers/error_controller.rb
   class ErrorController < Spectacular::Controller
    def not_found
      @response_code = 404
    end
   end




                         2a2653b2
What’s Left

• Only renders HAML
• No layouts
• Can’t easily render a different view
• No query parameters
• No POST
thanks

• Bryce Kerley; mercenary developer
• bkerley@brycekerley.net
• http://twitter.com/bonzoesc
• Code on Github: http://bit.ly/spectac

More Related Content

What's hot

Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.SWAAM Tech
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - IntroductionVagmi Mudumbai
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
Rails Engine :: modularize you app
Rails Engine :: modularize you appRails Engine :: modularize you app
Rails Engine :: modularize you appMuntasim Ahmed
 
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010Plataformatec
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Plataformatec
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular applicationmirrec
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
OpenTox API introductory presentation
OpenTox API introductory presentationOpenTox API introductory presentation
OpenTox API introductory presentationPantelis Sopasakis
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Rails Engines as a way to Micro services
Rails Engines as a way to Micro servicesRails Engines as a way to Micro services
Rails Engines as a way to Micro servicesLucas Alencar
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Vikas Chauhan
 

What's hot (20)

Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Rails Engine :: modularize you app
Rails Engine :: modularize you appRails Engine :: modularize you app
Rails Engine :: modularize you app
 
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
OpenTox API introductory presentation
OpenTox API introductory presentationOpenTox API introductory presentation
OpenTox API introductory presentation
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Rails Engines as a way to Micro services
Rails Engines as a way to Micro servicesRails Engines as a way to Micro services
Rails Engines as a way to Micro services
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2
 
Workshop Laravel 5.2
Workshop Laravel 5.2Workshop Laravel 5.2
Workshop Laravel 5.2
 

Viewers also liked

Sinatra: the Classiest of Prototypes
Sinatra: the Classiest of PrototypesSinatra: the Classiest of Prototypes
Sinatra: the Classiest of PrototypesBryce Kerley
 
Analysis Of Opening Techniques 1
Analysis Of Opening Techniques 1Analysis Of Opening Techniques 1
Analysis Of Opening Techniques 1guest58f2ad
 
Triskelion and Crapshoot
Triskelion and CrapshootTriskelion and Crapshoot
Triskelion and CrapshootBryce Kerley
 
Test and taste your aiming
Test and taste your aimingTest and taste your aiming
Test and taste your aimingDiana Ortiz
 
Analysis Of Opening Techniques The Shining
Analysis Of Opening Techniques  The ShiningAnalysis Of Opening Techniques  The Shining
Analysis Of Opening Techniques The Shiningguest58f2ad
 
Are you paying atenttion
Are you paying atenttionAre you paying atenttion
Are you paying atenttionDiana Ortiz
 
THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation
THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation
THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation Silverio Zebral Filho
 

Viewers also liked (7)

Sinatra: the Classiest of Prototypes
Sinatra: the Classiest of PrototypesSinatra: the Classiest of Prototypes
Sinatra: the Classiest of Prototypes
 
Analysis Of Opening Techniques 1
Analysis Of Opening Techniques 1Analysis Of Opening Techniques 1
Analysis Of Opening Techniques 1
 
Triskelion and Crapshoot
Triskelion and CrapshootTriskelion and Crapshoot
Triskelion and Crapshoot
 
Test and taste your aiming
Test and taste your aimingTest and taste your aiming
Test and taste your aiming
 
Analysis Of Opening Techniques The Shining
Analysis Of Opening Techniques  The ShiningAnalysis Of Opening Techniques  The Shining
Analysis Of Opening Techniques The Shining
 
Are you paying atenttion
Are you paying atenttionAre you paying atenttion
Are you paying atenttion
 
THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation
THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation
THE 9 GOLDEN-RULES: Climbing the ladder of problem-solving mediation
 

Similar to Rack is Spectacular

Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Alberto Perdomo
 
Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Henry S
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012rivierarb
 
Design Summit - Rails 4 Migration - Aaron Patterson
Design Summit - Rails 4 Migration - Aaron PattersonDesign Summit - Rails 4 Migration - Aaron Patterson
Design Summit - Rails 4 Migration - Aaron PattersonManageIQ
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009bturnbull
 
Using ArcGIS Server with Ruby on Rails
Using ArcGIS Server with Ruby on RailsUsing ArcGIS Server with Ruby on Rails
Using ArcGIS Server with Ruby on RailsDave Bouwman
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudHiro Asari
 
Umleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB appUmleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB appLenz Gschwendtner
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On RailsSteve Keener
 

Similar to Rack is Spectacular (20)

Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Speedy TDD with Rails
Speedy TDD with RailsSpeedy TDD with Rails
Speedy TDD with Rails
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Design Summit - Rails 4 Migration - Aaron Patterson
Design Summit - Rails 4 Migration - Aaron PattersonDesign Summit - Rails 4 Migration - Aaron Patterson
Design Summit - Rails 4 Migration - Aaron Patterson
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
 
Using ArcGIS Server with Ruby on Rails
Using ArcGIS Server with Ruby on RailsUsing ArcGIS Server with Ruby on Rails
Using ArcGIS Server with Ruby on Rails
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the Cloud
 
Umleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB appUmleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB app
 
Rack
RackRack
Rack
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 

Recently uploaded

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 

Recently uploaded (20)

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 

Rack is Spectacular

  • 1. Rack is Spectacular Learning Rack by making a cheap Rails knockoff
  • 2. WARNING CODE HEAVY HTTP Ruby Rails
  • 3. WARNING CODE HEAVY So get the code http://bit.ly/spectac c9c340bb
  • 4. WARNING CODE HEAVY NOT READY FOR PRODUCTION c9c340bb
  • 5. Rack • Standard Ruby-HTTP interface • Write (framework) once • Run anywhere (that is Rack-compatible) • Rails, Sinatra, Camping • Mongrel, Passenger, Unicorn
  • 6. A Rack Application config.ru use Rack::ContentLength   run(proc do   [ 200, { 'Content-type' => 'text/plain'}, 'hello world'] end) Response Code Response Headers Response Body c9c340bb
  • 7.
  • 8. What is Rails • ActionPack • Router - maps URLs to code • Controller - environment for code • View - generating response body • ActiveRecord - database access
  • 9. The Essential Rails • ActionPack • Router - maps URLs to code • Controller - environment for code • View - generating response body • ActiveRecord - database access
  • 10. config.ru require 'lib/spectacular.rb' use Rack::ContentLength   run(Spectacular::App.new) lib/spectacular/app.rb module Spectacular   class App     def call(environment)       [ 200, { 'Content-type' => 'text/plain'}, 'hello world']     end   end end 0fad6a02
  • 11.
  • 12. lib/spectacular/app.rb module Spectacular   class App …     def call(environment)       method = environment['REQUEST_METHOD']       path = environment['PATH_INFO']       @dispatcher.dispatch method, path, environment     rescue => exception       error_backtrace exception, environment     end       private     def error_backtrace(exception, environment)       exception_info = “some html”        [500, { 'Content-type' => 'text/html'}, exception_info]     end …   end end 2a0d1445
  • 13. lib/spectacular/app.rb module Spectacular   class App …     def call(environment) breaks; no dispatcher yet       method = environment['REQUEST_METHOD']       path = environment['PATH_INFO']       @dispatcher.dispatch method, path, environment     rescue => exception       error_backtrace exception, environment     end       private     def error_backtrace(exception, environment)       exception_info = “some html”        [500, { 'Content-type' => 'text/html'}, exception_info]     end …   end end 2a0d1445
  • 14.
  • 15. Dispatch & Routing are the most complicated parts of Rails [citation needed]
  • 16. But That’s Okay • We’re not building Rails • It’s okay if we Fail to Scale • Just use an array to map paths to controllers and actions
  • 17. lib/spectacular/dispatcher.rb     def get_route(path)       @routes.detect{ |r| path === r[0] }     end …     class RoutePen       def route(path, controller, method)         @routes << [path, controller, method]       end     end 9cfb9609
  • 18.
  • 19. lib/spectacular/controller.rb     def response_for(method)       @method = method       send @method       [response_code, headers, body]     end …     def template_file       File.join(APP_DIR, 'views', controller_name, "#{@method}.html.haml")     end …     def body       return @body if defined? @body       template = File.read template_file       engine = Haml::Engine.new template       @body = engine.render     end ce2f00a3
  • 20. app/controllers/hello_controller.rb class HelloController < Spectacular::Controller   def index   end end app/views/hello/index.html.haml hello world ce2f00a3
  • 21.
  • 22. Wildcards lib/spectacular/dispatcher.rb def get_route(path) @routes.detect{ |r| r[0] === path } end 48b08205
  • 23. === 0 :> /abc/ === 'abc' # => true 0 :> String === 'abc' # => true 0 :> /too+t/ === 'toooooooooot' # => true
  • 24. A Wildcard Route app/routes.rb route /too+t/, TootController, :toot 48b08205
  • 25. Using the Path app/controllers/toot_controller.rb class TootController < Spectacular::Controller def toot @toot = @path.gsub('/','') end end app/views/toot/toot.html.haml %h1=@toot 48b08205
  • 26.
  • 27.
  • 28. 404 • When we can’t figure out how to process a request, that should be a “404” • We can simply make a wildcard route
  • 29. app/routes.rb route //, ErrorController, :not_found app/controllers/error_controller.rb class ErrorController < Spectacular::Controller def not_found @response_code = 404 end end 2a2653b2
  • 30.
  • 31. What’s Left • Only renders HAML • No layouts • Can’t easily render a different view • No query parameters • No POST
  • 32. thanks • Bryce Kerley; mercenary developer • bkerley@brycekerley.net • http://twitter.com/bonzoesc • Code on Github: http://bit.ly/spectac