Rack
Upcoming SlideShare
Loading in...5
×
 

Rack

on

  • 1,911 views

A short presentation on Rack middleware I gave at the 10/21/2010 NovaRUG.

A short presentation on Rack middleware I gave at the 10/21/2010 NovaRUG.

Statistics

Views

Total Views
1,911
Slideshare-icon Views on SlideShare
1,911
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rack Rack Presentation Transcript

    • Rack Scott Leberknight
    • HTTP make request, get response
    • Request a hash containing the environment (headers, params, input stream)
    • Response status, headers, body
    • Simplest Rack App..
    • class Hello status def call(env) headers [ 200, { "Content-Type" => "text/plain" }, [ "Hello!", "Having fun yet?" ] ] end end body
    • Middleware Order Matters !
    • middlewares call() each other... and act like chain of response filters... ...so the order you use them matters!
    • init with app class Reverse def initialize(app) first, Call the app @app = app end def call(env) status, headers, body = @app.call(env) [status, headers, body.map { |b| b.reverse }] end end then, do your stuff
    • use Rack::ContentLength use RackExamples::Paragraphizer use RackExamples::Upcase use use RackExamples::Downcase RackExamples::Reverse Is output upper or app = lambda { |env| [ lower case? 200, { 'Content-Type' => 'text/html' }, ["Dammit, I'm mad!", "Was it a rat I saw?", "Madam, I'm Adam"] ] } run app 11
    • use Rack::ContentLength use RackExamples::Paragraphizer use RackExamples::Downcase use RackExamples::Upcase use RackExamples::Reverse How about now? app = lambda { |env| [ 200, { 'Content-Type' => 'text/html' }, ["Dammit, I'm mad!", "Was it a rat I saw?", "Madam, I'm Adam"] ] } run app 12
    • "Off t he Shelf"
    • Rack::ShowExceptions Rack::MailExceptions Rack::CommonLogger Rack::ContentLength Rack::JSON ActionController::StringCoercion Rack::ETag Rack::Deflater ...and lots more
    • Baked into Ra ils
    • $ rake middleware (in /Users/sleberkn/Projects/my-niclabs) use Rack::Lock use ActionController::Failsafe use ActionController::Session::CookieStore, #<Proc:0x00000001017acf18@(eval):8> use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActionController::StringCoercion use Rack::Deflater use Sass::Plugin::Rack use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache run ActionController::Dispatcher.new
    • Summary
    • References
    • http://lmgtfy.com/?q=ruby+rack http://www.letmebingthatforyou.com/?q=ruby+rack
    • Image credits Shelf thedesignblog.org/entry/odersoding-storage-system-doubles-as-a-room-divider/ Cool newgeography.com Baking haileythebaketress.blogspot.com Json nearinfinity.com
    • scott.leberknight@nearinfinity.com www.nearinfinity.com/blogs/ twitter: sleberknight