an introduction to ruby web frameworks
TRANSCRIPT
An Introduction to Ruby Web Frameworks
Ryan Carmelo BrionesServer Monkey / Code Samurai, Edgecase, LLC
Commanding Your SSH Universe with Capistrano
Thurs 5/24 5:20 PM in Portland 251
An Introduction to Ruby Web Frameworks
Ryan Carmelo BrionesServer Monkey / Code Samurai, Edgecase, LLC
0 to Ruby in 45 minutes
Define: Framework
FrameworkResuable
FrameworkEncapsulated
FrameworkDomain Specific!
Why Ruby?
RubyReady to lead Object Oriented since day 1
User.all.reject { |user| user.admin? }.each do |user| user.expire 1.days.from_now user.saveend
RubyFine-grained Control
User.all.reject { |user| user.admin? }.each do |user| user.expire 1.days.from_now user.saveend
RubyPromotes Beautiful Code
User.all.reject { |user| user.admin? }.each do |user| user.expire 1.days.from_now user.saveend
RubyMRI has performance issues
RubyLibraries?
RubyAlternative Implementations
YARV(aka Ruby 1.9)
Ruby Frameworks
Rack
RackResponding to the #call
class HelloWorld def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello world!"]] endend
RackLet the handlers do the
work
Ruby on Rails
RailsCode Generation
RailsCode Generation
RailsConvention over Configuration
• Naming Conventions• conference_registrations• conference_registration.rb• ConferenceRegistration < ActiveRecord::Base
• Load Paths
• Naming Conventions• conference_registrations• conference_registration.rb• ConferenceRegistration < ActiveRecord::Base
• Load Paths
RailsConvention over Configuration
Opinionated Software / “The Golden Path”
RailsDomain Specific Languages
# models
class Publication < ActiveRecord::Basehas_many :subscriptionshas_many :subscribers, :through => :subscriptions,
:class_name => ‘User’end
# rails router
ActionController::Routing::Routes.draw do |map|map.resources :publications, :has_many => [:subscriptions]map.resources :users
map.login ‘/login’, :controller => ‘sessions’, :action => ‘login’map.connect ‘:controller/:action/:id’
end
RailsFirst-class Testing
RailsToo much magic
RailsMoving to fast?
Merb
MerbAll you need, nil you don’t
MerbEschews “magic”
MerbChallenge: Benchmark and
Profile
MerbFlexible == Unproductive?
MerbResources / Documentation
Camping
CampingAll in one file / Rapid Prototypes#!/usr/bin/env rubyrequire ‘rubygems’require ‘camping’
Camping.goes :Foo
module Foo::Controllersclass Home < R ‘/’def getrender :home_index
endend
end
module Foo::Viewsdef home_indexh1 ‘Home’
endend
CampingAll in one file / Rapid Prototypes#!/usr/bin/env rubyrequire ‘rubygems’require ‘camping’
Camping.goes :Foo
module Foo::Controllersclass Home < R ‘/’def getrender :home_index
endend
end
module Foo::Viewsdef home_indexh1 ‘Home’
endend
# setup app namespace
CampingAll in one file / Rapid Prototypes#!/usr/bin/env rubyrequire ‘rubygems’require ‘camping’
Camping.goes :Foo
module Foo::Controllersclass Home < R ‘/’def getrender :home_index
endend
end
module Foo::Viewsdef home_indexh1 ‘Home’
endend
# route request to http://app/
# setup app namespace
CampingAll in one file / Rapid Prototypes#!/usr/bin/env rubyrequire ‘rubygems’require ‘camping’
Camping.goes :Foo
module Foo::Controllersclass Home < R ‘/’def getrender :home_index
endend
end
module Foo::Viewsdef home_indexh1 ‘Home’
endend
# route request to http://app/# route get requests to http://app/
# setup app namespace
CampingAll in one file / Rapid Prototypes#!/usr/bin/env rubyrequire ‘rubygems’require ‘camping’
Camping.goes :Foo
module Foo::Controllersclass Home < R ‘/’def getrender :home_index
endend
end
module Foo::Viewsdef home_indexh1 ‘Home’
endend
# route request to http://app/# route get requests to http://app/# render home_index view
# setup app namespace
CampingSmall apps, Many mounts
CampingStructure translates to other
popular MVCs
CampingNo standard test framework
Sinatra
SinatraSimple. Fast. Effective.
#!/usr/bin/env rubyrequire ‘rubygems’require ‘sinatra’
get ‘/’ do“Hello, World!”
end
Extra Credit
IOWARamazeWavesMavericMackNitroWuby
Questions?
Thank You
http://brionesandco.com/ryanbrioneshttp://theedgecase.com
http://blog.theedgecase.com