Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Sinatra Pattern 20130415

15,806 views

Published on

Published in: Technology, Education
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Sinatra Pattern 20130415

  1. 1. ちっちゃくはじめて おっきく育てる sinataraアプリの作り方 SEO Naotoshi (@sonots)
  2. 2. 自己紹介 describe Sonots do its(:company) { should == :DeNA } it_should_behave_like “DeNA employee” end shared_examples_for “DeNA employee” do it { should write(:perl) } #=> fail end
  3. 3. 最近やってること Haikanko ※ このロゴはフィクションであり(ry
  4. 4. 誰かが言ってた sinatraってアプリが小さ い時はいいけど、大きく なるとお辛いんでしょう?
  5. 5. そんなこと ないよ
  6. 6. ちっちゃくはじめておっきく 育てる 俺の最強 Sinatra パターン をお伝えします
  7. 7. ところで ruby 2.0 で何の問題もな く動いているので、ruby 2.0関連の話は何もなし...
  8. 8. さっそく コード中心で><
  9. 9. 基礎 ∼ クラシックスタイル require 'sinatra'   get '/hello' do 'Hello World!' end   get '/hello/:name' do "Hello #{params[:name]}!" end $ ruby my_app.rb Gemfile Gemfile.lock my_app.rb 起動 ディレクトリ構造 my_app.rb
  10. 10. モジュラースタイル require 'sinatra/base'  class MyApp < Siantra::Base get '/hello' do 'Hello World!' end   get '/hello/:name' do "Hello #{params[:name]}!" end end $ rackup Gemfile Gemfile.lock config.ru my_app.rb 起動 ディレクトリ構造 # config.ru require './my_app' run MyApp
  11. 11. Controller 足したい
  12. 12. 1. Sinatra.register を使う # my_app.rb require 'sinatra/base' require_relative 'posts_controller' class MyApp < Sinatra::Base   register PostsController   get '/hello' do     'Hello World!'   end      get '/hello/:name' do     "Hello #{params[:name]}!"   end end Gemfile Gemfile.lock config.ru my_app.rb posts_controller.rb ディレクトリ # posts_controller.rb module PostsController   def self.registered(app)     app.get '/posts' do     end     app.get '/posts/:id' do       "Post #{params[:id]}"     end   end end
  13. 13. app.get とかキモい
  14. 14. 2. use (Rack Middleware) # my_app.rb class MyApp < Sinatra::Base   get '/hello' do     'Hello World!'   end      get '/hello/:name' do     "Hello #{params[:name]}!"   end end Gemfile Gemfile.lock config.ru my_app.rb posts_controller.rb ディレクトリ # posts_controller.rb class PostsController < Sinatra::Base   get '/posts' do   end   get '/posts/:id' do     "Post #{params[:id]}"   end end # config.ru require 'sinatra/base' require './my_app' require './posts_controller' use PostsController run MyApp
  15. 15. まぁまぁ
  16. 16. 本命: URLMap を使う class HelloController < Sinatra::Base   get '/hello' do     'Hello World!'   end      get '/hello/:name' do     "Hello #{params[:name]}!"   end end Gemfile Gemfile.lock config.ru hello_controller.rb posts_controller.rb ディレクトリ class PostsController < Sinatra::Base   get '/' do   end   get '/:id' do     "Post #{params[:id]}"   end end require 'sinatra/base' require './hello_controller' require './posts_controller' ROUTES = {   '/' => HelloController,   '/posts' => PostsController, } run Rack::URLMap.new(ROUTES) config.ru
  17. 17. View 足したい
  18. 18. View ∼ Sinatraにあるよ class HelloController < Sinatra::Base   set :views, File.expand_path('../views', File.dirname(__FILE__))      get '/hello' do     'Hello World!'   end   get '/hello/:name' do     @name = params[:name]     erb :hello   end end Gemfile Gemfile.lock config.ru controllers/ views/ ディレクトリ <html>   <b>Hello <%= @name %>!</b> </html> views/hello.erb
  19. 19. Model 足したい
  20. 20. Model ∼ ActiveRecordとか source 'https://rubygems.org' gem 'sinatra', require: 'sinatra/base' gem 'activesupport' gem 'activerecord' gem 'sinatra-activerecord',:require => 'sinatra/activerecord' gem 'sqlite3' gem 'rake' require 'active_record' ActiveRecord::Base.establish_connection(   :adapter => 'sqlite3',   :host => 'localhost',   :username => 'USERNAME', #or root   :password => 'PASSWORD',   :database => 'db/YOURDATABASE' ) class Post < ActiveRecord::Base end models/post.rb Gemfile Gemfile Gemfile.lock config.ru controllers/ views/ models/ ディレクトリ
  21. 21. MVC った ^^
  22. 22. けど
  23. 23. Worker 欲しくなった
  24. 24. Worker + gem 'foreman’ ディレクトリ web: bundle exec rackup web/config.ru worker: bundle exec ruby worker/notification.rb worker/notification.rb Gemfile Gemfile Gemfile.lock config.ru web/ controllers/ views/ models/ worker/ require_relative '../models/post.rb' class Notification   def run     while true       sleep 1       puts "hey! #{Post.all.first}"     end   end end Notification.new.run Procfile $ foreman start 起動
  25. 25. まとめ • 最初はちっちゃくリーンスタートアップ • おっきくなっても破綻しない!(Rails っぽくし ていけば) • いつ Sinatra やるの?今でしょ! • コード https://github.com/sonots/sinatra-practice

×