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

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

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