Slide 1

Slide 1 text

Ruby micro frameworks пятница, 28 декабря 12 г.

Slide 2

Slide 2 text

Purposes Few-pages sites Landing pages Api Prototipes пятница, 28 декабря 12 г.

Slide 3

Slide 3 text

Simple and Fast пятница, 28 декабря 12 г.

Slide 4

Slide 4 text

Rails stack controllers models views database mails tasks assets logging tests authentications plugins generators routing пятница, 28 декабря 12 г.

Slide 5

Slide 5 text

пятница, 28 декабря 12 г.

Slide 6

Slide 6 text

пятница, 28 декабря 12 г.

Slide 7

Slide 7 text

Do you think your Wu-Tang Sword can defeat me? пятница, 28 декабря 12 г.

Slide 8

Slide 8 text

Rack! пятница, 28 декабря 12 г.

Slide 9

Slide 9 text

Padrino (alive) Merb (dead) Hobo (dead) Camping (dead) Remaze (alive) Cuba (half-alive) Sinatra (alive) Rails-api (just borned) Solutions пятница, 28 декабря 12 г.

Slide 10

Slide 10 text

small blog static pages api Cognizance in comparison пятница, 28 декабря 12 г.

Slide 11

Slide 11 text

Blogs for everyone пятница, 28 декабря 12 г.

Slide 12

Slide 12 text

Cuba пятница, 28 декабря 12 г.

Slide 13

Slide 13 text

Rack middleware Security Testing with Cutest and Capibara Own plugins $ gem install cuba пятница, 28 декабря 12 г.

Slide 14

Slide 14 text

Hello, Cuba! $ gem install cuba require "cuba" require "cuba/render" Cuba.plugin Cuba::Render Cuba.define do on get do on "hello" do res.write render("hello.haml", content: "Hello, Cuba") end on root do res.redirect "/hello" end end end пятница, 28 декабря 12 г.

Slide 15

Slide 15 text

$ gem install cuba require "ohm" Ohm.connect(host: "localhost", port: "6379") class Blog < Ohm::Model attribute :title attribute :text end attribute set list reference collection пятница, 28 декабря 12 г.

Slide 16

Slide 16 text

• Fast • Simple • Extendable Pros and Cons 3ms vs Rails’ 13ms Che pleased пятница, 28 декабря 12 г.

Slide 17

Slide 17 text

Sinatra пятница, 28 декабря 12 г.

Slide 18

Slide 18 text

Rack middleware Routing Conditions Filters Helpers Template engines %w(erb haml sass less markdown etc) Security Cache Error handling No database support No restful routing $ gem install sinatra пятница, 28 декабря 12 г.

Slide 19

Slide 19 text

Libraries Modular and Classic Apps Sinatra as Middleware (Rails/Cuba/ Camping) Api Endpoint $ gem install sinatra пятница, 28 декабря 12 г.

Slide 20

Slide 20 text

$ gem install sinatra # classic style require 'sinatra' require 'sinatra/linkblocker' block_links_from 'digg.com' get "/events/recent.json" do Event.recent.to_json end # modular style require 'sinatra/base' require 'sinatra/diggblocker' module Posts class Application < Sinatra::Base register Sinatra::LinkBlocker block_links_from 'digg.com' get "/" do erb :index end end end пятница, 28 декабря 12 г.

Slide 21

Slide 21 text

$ gem install sinatra require 'sinatra/base' class LoginScreen < Sinatra::Base enable :sessions get('/login') { haml :login } post('/login') do if params[:name] == 'admin' && params[:password] == 'admin' session['user_name'] = params[:name] else redirect '/login' end end end class MyApp < Sinatra::Base # middleware will run before filters use LoginScreen before do unless session['user_name'] halt "Access denied, please login." end end get('/') { "Hello #{session['user_name']}." } end # config/routes.rb mount API::Endpoints, :at => "/api" пятница, 28 декабря 12 г.

Slide 22

Slide 22 text

Fast Simple Overlaped with Rails +HTTP -HTML Many lines not for pros Doens’t support some gems Pros and Cons пятница, 28 декабря 12 г.

Slide 23

Slide 23 text

Rails-Api пятница, 28 декабря 12 г.

Slide 24

Slide 24 text

use ActionDispatch::Static use Rack::Lock use Rack::Runtime use ActionDispatch::RequestId use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActionDispatch::ParamsParser use ActionDispatch::Head use Rack::ConditionalGet use Rack::ETag run ApiApp::Application.routes use ActionDispatch::Static use Rack::Lock use Rack::Runtime use Rack::MethodOverride use ActionDispatch::RequestId use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActionDispatch::Cookies use ActionDispatch::Session::CookieStore use ActionDispatch::Flash use ActionDispatch::ParamsParser use ActionDispatch::Head use Rack::ConditionalGet use Rack::ETag use ActionDispatch::BestStandardsSupport run Application::Application.routes $ gem install rails-api пятница, 28 декабря 12 г.

Slide 25

Slide 25 text

$ gem install rails-api find 10 differences AbstractController::Layouts AbstractController::Translation AbstractController::AssetPaths Helpers HideActions UrlFor Redirecting Rendering Renderers::All ConditionalGet RackDelegation Caching MimeResponds ImplicitRender Cookies Flash RequestForgeryProtection ForceSSL Streaming DataStreaming RecordIdentifier HttpAuthentication::Basic::ControllerMethods HttpAuthentication::Digest::ControllerMethods HttpAuthentication::Token::ControllerMethods AbstractController::Callbacks Rescue ActionController::UrlFor ActionController::Redirecting ActionController::Rendering ActionController::Renderers::All ActionController::ConditionalGet ActionController::ForceSSL ActionController::RackDelegation ActionController::DataStreaming AbstractController::Callbacks ActionController::Instrumentation ActionController::Rescue пятница, 28 декабря 12 г.

Slide 26

Slide 26 text

Benchmarks Framework | Requests/s ----------|----------- Rack | 2217 Cuba | 1975 Sinatra | 950 Rails | 535 Framework | LOC ----------|----------- Cuba | 152 Sinatra | 1476 Rails(AP) | 13181 пятница, 28 декабря 12 г.

Slide 27

Slide 27 text

http://rack.github.com/ http://cuba.is http://www.sinatrarb.com https://github.com/rails-api/rails-api http://rubyonrails.org/ пятница, 28 декабря 12 г.

Slide 28

Slide 28 text

пятница, 28 декабря 12 г.

Slide 29

Slide 29 text

пятница, 28 декабря 12 г.

Slide 30

Slide 30 text

Sergeev Petr [email protected] @i_feya @evercodelab пятница, 28 декабря 12 г.