Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rack is Spectacular
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Bryce "BonzoESC" Kerley
February 21, 2010
Programming
70
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rack is Spectacular
Barcamp Miami 2010
Bryce "BonzoESC" Kerley
February 21, 2010
More Decks by Bryce "BonzoESC" Kerley
See All by Bryce "BonzoESC" Kerley
Ruby in 2020
bryce
1
130
Rails and the Internet of Things
bryce
1
91
It's Not Ruby, But…
bryce
0
87
Ruby 2.5: What's New and What's Cool
bryce
0
93
docker for rubyists
bryce
0
120
Would You Like To Make A Game?
bryce
0
67
WebSockets and ActionCable
bryce
0
96
How I Learned to Stop Worrying and Like RSpec
bryce
0
89
How Do Computers Even Work?
bryce
1
220
Other Decks in Programming
See All in Programming
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
150
What's New in Android 2026
veronikapj
0
230
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
410
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
250
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
180
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
280
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
550
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
580
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
260
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
180
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
320
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
550
Featured
See All Featured
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
420
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.1k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
It's Worth the Effort
3n
188
29k
Typedesign – Prime Four
hannesfritz
42
3.1k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Color Theory Basics | Prateek | Gurzu
gurzu
0
400
Site-Speed That Sticks
csswizardry
13
1.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
Being A Developer After 40
akosma
91
590k
Transcript
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 use Rack::ContentLength run(proc do [ 200, {
'Content-type' => 'text/plain'}, 'hello world'] end) Response Code Response Headers Response Body c9c340bb config.ru
None
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
module Spectacular class App def call(environment) [ 200, { 'Content-type'
=> 'text/plain'}, 'hello world'] end end end require 'lib/spectacular.rb' use Rack::ContentLength run(Spectacular::App.new) config.ru lib/spectacular/app.rb 0fad6a02
None
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 lib/spectacular/app.rb 2a0d1445 breaks; no dispatcher yet
None
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
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/dispatcher.rb
None
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 lib/spectacular/controller.rb
class HelloController < Spectacular::Controller def index end end hello world
app/controllers/hello_controller.rb app/views/hello/index.html.haml ce2f00a3
None
Wildcards def get_route(path) @routes.detect{ |r| r[0] === path } end
lib/spectacular/dispatcher.rb 48b08205
=== 0 :> /abc/ === 'abc' # => true 0
:> String === 'abc' # => true 0 :> /too+t/ === 'toooooooooot' # => true
route /too+t/, TootController, :toot app/routes.rb A Wildcard Route 48b08205
Using the Path class TootController < Spectacular::Controller def toot @toot
= @path.gsub('/','') end end app/controllers/toot_controller.rb %h1=@toot app/views/toot/toot.html.haml 48b08205
None
None
404 • When we can’t figure out how to process
a request, that should be a “404” • We can simply make a wildcard route
route //, ErrorController, :not_found app/routes.rb class ErrorController < Spectacular::Controller def
not_found @response_code = 404 end end app/controllers/error_controller.rb 2a2653b2
None
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 •
[email protected]
• http://twitter.com/bonzoesc
• Code on Github: http://bit.ly/spectac