And the Greatest of These Is ... Rack Support

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1



    Lots of awesome things coming to Rails









    standard API for all Ruby web frameworks




    ruby-prof, benchmark application

    replacement for exception notifier (but pay attention later)

    not in rack core
    ryan tomayko - earlier session?

    chain sinatra/merb/other rack apps
    file upload separate from main app






    script/server
    from railties/lib/commands/server.rb


    Rails version of Rack::Cascade


    talk about the poller example

    unit testing for the individual metal action
    integration testing for overall testing

    Adam Wiggins talked about this in his session yesterday


















    135ms for hybrid, which is 21% of the standard

    lame tests I employed showed the same or greater effect

    66ms for hybrid v2, 10.6% of standard and 48% of hybrid





















    cooperation - multiple people contributing to each other, like Double Dragon!
    this blonde guy is clearly in trouble, but if he had his buddy helping he’d be golden


    2 Favorites

    And the Greatest of These Is ... Rack Support - Presentation Transcript

    1. And the Greatest of These Is... Rack Support Ben Sco eld – Viget Labs
    2. #?forben
    3. Application Templates
    4. Nested Attribute Assignment ickr: angelrays
    5. ActiveRecord::Base#touch ickr: jjjohn
    6. Rack
    7. def call(env) [ status, # 200 headers, # {\"Content-Type\" => \"text/html\"} body # [\"<html>...</html>\"] ] end
    8. request application response
    9. request middleware application middleware response
    10. Rack::Pro ler ickr: oberazzi
    11. Rack::MailExceptions ickr: warmnfuzzy
    12. Rack::Cache ickr: timpatterson
    13. rack::cascade Rack::Cascade ickr: _at
    14. Rack in Rails
    15. > rake middleware use Rack::Lock use ActionDispatch::Failsafe use ActionDispatch::ShowExceptions, [true] use ActionDispatch::Rescue, [#<Method: ...>] use ActionDispatch::Session::CookieStore, [{...}] use ActionDispatch::ParamsParser use Rack::MethodOverride use Rack::Head use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache run ActionController::Dispatcher.new
    16. > rake middleware use Rack::Lock use ActionDispatch::Failsafe use ActionDispatch::ShowExceptions, [true] use ActionDispatch::Rescue, [#<Method: ...>] use ActionDispatch::Session::CookieStore, [{...}] use ActionDispatch::ParamsParser use Rack::MethodOverride use Rack::Head use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache run ActionController::Dispatcher.new
    17. app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] use Rails::Rack::Debugger if options[:debugger] map \"/\" do use Rails::Rack::Static run ActionController::Dispatcher.new end }.to_app
    18. Rails::Initializer.run do |config| config.middleware.insert_before Rack::Head, Ben::Asplode config.middleware.swap Rack::Lock, Ben::Lock config.middleware.use Rack::MailExceptions end
    19. Metal ickr: lrargerich
    20. http://www.kiwibean.com/
    21. PLEASE testing metalBY STAND EXPAND: THIS IS ONLY A TEST
    22. METAL Sinatra
    23. Cool Tricks
    24. Rack::Bug ickr: catdancing
    25. requires </body>
    26. Progressive Caching
    27. Progressive Caching
    28. Progressive Caching
    29. class SessionsController < ApplicationController def create # ... session[:personalize] = { :logged_in => true, :quicklist => current_user.quicklist.episode_ids, :subscriptions => current_user.subscription_ids } end end
    30. class ChannelsController < ApplicationController caches_page :show def show @channel = Channel.find(params[:id]) end end
    31. $(document).ready(function() { $.getJSON('/personalize', function(data) { // identify quicklisted episodes $.each(data['quicklist'], function() { $('#episode_'+this).addClass('listed'); }); // switch navigation if (data['logged_in']) { $('#logged_in_nav').show(); } // etc. }); });
    32. class Personalizer def self.call(env) if env[\"PATH_INFO\"] =~ /^/personalize/ [ 200, {\"Content-Type\" => \"application/javascript\"}, env['rack.session'][:personalize].to_json ] else [404, {\"Content-Type\" => \"text/html\"}, [\"Not Found\"]] end end end
    33. class PullList def self.call(env) if env[\"PATH_INFO\"] =~ /^\\/pulls/ [ 200, {\"Content-Type\" => \"application/javascript\"}, [Pull.by_user(user).for_date(date).map {|i| i.item_id}.to_json]] else [404, {\"Content-Type\" => \"text/html\"}, [\"Not Found\"]] end end end standard 0.617 progressive 0.039 0.096
    34. class PullList def self.call(env) if env[\"PATH_INFO\"] =~ /^\\/pulls/ [ 200, {\"Content-Type\" => \"application/javascript\"}, [env['rack.session'][:pulls].to_json] ] else [404, {\"Content-Type\" => \"text/html\"}, [\"Not Found\"]] end end end standard 0.617 progressive 0.039 0.096 progressive v2 0.043 0.023
    35. DIY
    36. request middleware application middleware response
    37. Rack::Embiggener
    38. class Embiggener < Test::Unit::TestCase def test_embiggener_should_embiggen_known_url body = [\"Hello! I'm at http://tinyurl.com/cjmhva\"] assert_equal [\"Hello! I'm at http://www.culann.com\"], Rack:: Embiggener.embiggen_urls(body) end def test_embiggener_should_embiggen_multiple_urls body = [ \"Hello! I'm at http://tinyurl.com/cjmhva\", \"And I'm at http://tinyurl.com/cjmhva\" ] assert_equal [ \"Hello! I'm at http://www.culann.com\", \"And I'm at http://www.culann.com\" ], Rack::Embiggener.embiggen_urls(body) end end
    39. module Rack class Embiggener def self.embiggen_urls(original_body) new_body = [] original_body.each { |line| tinys = line.scan(/(http:\\/\\/(?:www\\.)?tinyurl\\.com\\/(.{6}))/) new_body << tinys.uniq.inject(line) do |body, tiny| original_tiny = tiny[0] preview_url = \"http://preview.tinyurl.com/#{tiny[1]}\" response = Net::HTTP.get_response(URI.parse(preview_url)) embiggened_url = response.body.match(/redirecturl\" href=\"(.*)\">/)[1] body.gsub(original_tiny, embiggened_url) end } new_body end # ... end end
    40. module Rack class Embiggener # ... def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) headers.delete('Content-Length') response = Rack::Response.new( Rack::Embiggener.embiggen_urls(body), status, headers ) response.finish return response.to_a end end end
    41. WARNING exception handling
    42. formerly: WARNING exception handling
    43. Rack::Hoptoad* * unofficial; thoughtbot is not responsible for this middleware; do not taunt rack::hoptoad; pregnant women should consult their doctors before using rack::hoptoad
    44. > rake middleware use Rack::Lock use ActionDispatch::Failsafe use ActionDispatch::ShowExceptions, [true] use ActionDispatch::Rescue, [#<Method: ...>] use ActionDispatch::Session::CookieStore, [{...}] use ActionDispatch::ParamsParser use Rack::MethodOverride use Rack::Head use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache run ActionController::Dispatcher.new
    45. Rails::Initializer.run do |config| # ... config.middleware.delete ActionDispatch::ShowExceptions config.middleware.delete ActionDispatch::Rescue config.middleware.use 'Rack::Hoptoad', 'my-hoptoad-api-key' config.middleware.use 'Rack::ShowExceptions' end
    46. module Rack class Hoptoad def initialize(app, api_key) @app = app @api_key = api_key end def call(env) @app.call(env) rescue => exception notify_hoptoad(exception, env) raise exception end # ... end end
    47. module Rack class Hoptoad def notify_hoptoad(exception, env) headers = { 'Content-type' => 'application/x-yaml', 'Accept' => 'text/xml, application/xml' } url = URI.parse(\"http://hoptoadapp.com/notices\") http = Net::HTTP.new(url.host, url.port) data = { :api_key => @api_key, :error_message => \"#{exception.class}: #{exception}\", :backtrace => exception.backtrace, :request => {}, :session => env['rack.session'], :environment => env } response = http.post( url.path, stringify_keys(:notice => data).to_yaml, headers ) if response != Net::HTTPSuccess # Hoptoad post failed end end end end
    48. Intangibles
    49. Thank You ben sco eld - @bsco eld - http://www.viget.com/extend - http://www.speakerrate.com/bsco eld

    + Ben ScofieldBen Scofield, 6 months ago

    custom

    1263 views, 2 favs, 1 embeds more stats

    Presentation given at Railsconf 2009, about Rack su more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1263
      • 1226 on SlideShare
      • 37 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 15
    Most viewed embeds
    • 37 views on http://www.viget.com

    more

    All embeds
    • 37 views on http://www.viget.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories