an introduction to ruby web frameworks

48
An Introduction to Ruby Web Frameworks Ryan Carmelo Briones Server Monkey / Code Samurai, Edgecase, LLC

Upload: others

Post on 12-Sep-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Introduction to Ruby Web Frameworks

An Introduction to Ruby Web Frameworks

Ryan Carmelo BrionesServer Monkey / Code Samurai, Edgecase, LLC

Page 2: An Introduction to Ruby Web Frameworks

Commanding Your SSH Universe with Capistrano

Thurs 5/24 5:20 PM in Portland 251

Page 3: An Introduction to Ruby Web Frameworks

An Introduction to Ruby Web Frameworks

Ryan Carmelo BrionesServer Monkey / Code Samurai, Edgecase, LLC

Page 4: An Introduction to Ruby Web Frameworks

0 to Ruby in 45 minutes

Page 5: An Introduction to Ruby Web Frameworks

Define: Framework

Page 6: An Introduction to Ruby Web Frameworks

FrameworkResuable

Page 7: An Introduction to Ruby Web Frameworks

FrameworkEncapsulated

Page 8: An Introduction to Ruby Web Frameworks

FrameworkDomain Specific!

Page 9: An Introduction to Ruby Web Frameworks

Why Ruby?

Page 10: An Introduction to Ruby Web Frameworks

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

Page 11: An Introduction to Ruby Web Frameworks

RubyFine-grained Control

User.all.reject { |user| user.admin? }.each do |user| user.expire 1.days.from_now user.saveend

Page 12: An Introduction to Ruby Web Frameworks

RubyPromotes Beautiful Code

User.all.reject { |user| user.admin? }.each do |user| user.expire 1.days.from_now user.saveend

Page 13: An Introduction to Ruby Web Frameworks

RubyMRI has performance issues

Page 14: An Introduction to Ruby Web Frameworks

RubyLibraries?

Page 15: An Introduction to Ruby Web Frameworks

RubyAlternative Implementations

YARV(aka Ruby 1.9)

Page 16: An Introduction to Ruby Web Frameworks

Ruby Frameworks

Page 17: An Introduction to Ruby Web Frameworks

Rack

Page 18: An Introduction to Ruby Web Frameworks

RackResponding to the #call

class HelloWorld def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello world!"]] endend

Page 19: An Introduction to Ruby Web Frameworks

RackLet the handlers do the

work

Page 20: An Introduction to Ruby Web Frameworks

Ruby on Rails

Page 21: An Introduction to Ruby Web Frameworks

RailsCode Generation

Page 22: An Introduction to Ruby Web Frameworks

RailsCode Generation

Page 23: An Introduction to Ruby Web Frameworks

RailsConvention over Configuration

• Naming Conventions• conference_registrations• conference_registration.rb• ConferenceRegistration < ActiveRecord::Base

• Load Paths

Page 24: An Introduction to Ruby Web Frameworks

• Naming Conventions• conference_registrations• conference_registration.rb• ConferenceRegistration < ActiveRecord::Base

• Load Paths

RailsConvention over Configuration

Opinionated Software / “The Golden Path”

Page 25: An Introduction to Ruby Web Frameworks

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

Page 26: An Introduction to Ruby Web Frameworks

RailsFirst-class Testing

Page 27: An Introduction to Ruby Web Frameworks

RailsToo much magic

Page 28: An Introduction to Ruby Web Frameworks

RailsMoving to fast?

Page 29: An Introduction to Ruby Web Frameworks

Merb

Page 30: An Introduction to Ruby Web Frameworks

MerbAll you need, nil you don’t

Page 31: An Introduction to Ruby Web Frameworks

MerbEschews “magic”

Page 32: An Introduction to Ruby Web Frameworks

MerbChallenge: Benchmark and

Profile

Page 33: An Introduction to Ruby Web Frameworks

MerbFlexible == Unproductive?

Page 34: An Introduction to Ruby Web Frameworks

MerbResources / Documentation

Page 35: An Introduction to Ruby Web Frameworks

Camping

Page 36: An Introduction to Ruby Web Frameworks

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

Page 37: An Introduction to Ruby Web Frameworks

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

Page 38: An Introduction to Ruby Web Frameworks

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

Page 39: An Introduction to Ruby Web Frameworks

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

Page 40: An Introduction to Ruby Web Frameworks

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

Page 41: An Introduction to Ruby Web Frameworks

CampingSmall apps, Many mounts

Page 42: An Introduction to Ruby Web Frameworks

CampingStructure translates to other

popular MVCs

Page 43: An Introduction to Ruby Web Frameworks

CampingNo standard test framework

Page 44: An Introduction to Ruby Web Frameworks

Sinatra

Page 45: An Introduction to Ruby Web Frameworks

SinatraSimple. Fast. Effective.

#!/usr/bin/env rubyrequire ‘rubygems’require ‘sinatra’

get ‘/’ do“Hello, World!”

end

Page 46: An Introduction to Ruby Web Frameworks

Extra Credit

IOWARamazeWavesMavericMackNitroWuby

Page 47: An Introduction to Ruby Web Frameworks

Questions?