SlideShare a Scribd company logo
1 of 49
Download to read offline
Ruby off Rails

 by Stoyan Zhekov
Kyoto, 17-May-2008
自己紹介
●   名前: ストヤン ジェコフ
●   ブルガリア人
●   3人男の子のパパ
内容
 ●   Coupling and Cohesion
 ●   ウェブアプリに必要なこと
 ●   ORM - Sequel (簡単な見解)
 ●   Ruby ウェブエボリューション
 ●   Enter Rack - The Middle Man
 ●   Thin, Ramaze, Tamanegi
 ●   まとめ, その他, 質問

08/05/19                           3
Coupling and Cohesion (1)
 ●   Cohesion - 凝集度 (ぎょうしゅうど)
       http://en.wikipedia.org/wiki/Cohesion_(computer_science)
 ●   Coupling - 結合度 (けつごうど)
       http://en.wikipedia.org/wiki/Coupling_(computer_science)




08/05/19                                                          4
Coupling and Cohesion (2)

正しいウェブアプリの組み立て方
● High cohesion


       –   少ない動作でたかい機能性
 ●   Low (loosely) coupling
       –   簡単な入れ替え




08/05/19                                5
Coupling and Cohesion (3)




             Google vs Amazon



08/05/19                               6
Coupling and Cohesion (5)




                     VS




08/05/19                               7
Railsについて




08/05/19               8
Ruby on Rails
 ●   全部セットでよかった。しかし、今は?
 ●   Convention over configuration – いいのか?
 ●   DRY – 可能?
       –   Generators
       –   Plugins
       –   Libraries




08/05/19                                     9
Railsなしの人生




             できる?



08/05/19                10
ウェブアプリに必要なこと
   ●   データベースの使い方: ORM
   ●   Request手順: CGI env, アップロード
   ●   ルーティング: URLとクラスの組み合わせ
   ●   Rendering (views): rendering libraries
   ●   Sessions: persist objects or data




08/05/19                                        11
Database ORM
 ●   Active Record ?= ActiveRecord
 ●   ActiveRecord – たくさんの問題点
       –   http://datamapper.org/why.html
 ●   Data Mapper – 早いけどまだ未完
       –   まだコンポジットキーなし
       –   自分のDBドライバーが必要
 ●   Sequel – よし。気に入ってる。


08/05/19                                    12
ORM – Sequel (なぜ?)
 ●   Pure Ruby
 ●   Thread safe
 ●   Connection pooling
 ●   DB queries構築のためのDSL
 ●   ObjectとDBレコードの組み合わせの軽いORM
 ●   Transactions with rollback



08/05/19                          13
ORM – Sequel (Core)
 ●   データベースのつなげ方
      require 'sequel'
      DB = Sequel.open 'sqlite:///blog.db'


      DB = Sequel.open 'postgres://cico:12345@localhost:5432/mydb'


      DB = Sequel.open(quot;postgres://postgres:postgres@localhost/my_dbquot;,
       :max_connections => 10, :logger => Logger.new('log/db.log'))




08/05/19                                                                 14
ORM – Sequel (Core, 2)
DB << quot;CREATE TABLE users (name VARCHAR(255) NOT NULL)quot;

DB.fetch(quot;SELECT name FROM usersquot;) do |row|
 p r[:name]
end


dataset = DB[:managers].where(:salary => 50..100).order(:name, :department)


paginated = dataset.paginate(1, 10) # first page, 10 rows per page
paginated.page_count #=> number of pages in dataset
paginated.current_page #=> 1



08/05/19                                                                      15
ORM – Sequel (Model)
           class Post < Sequel::Model(:my_posts)
             set_primary_key [:category, :title]

            belongs_to :author
            has_many :comments
            has_and_belongs_to_many :tags

            after_create do
              set(:created_at => Time.now)
            end

           end



08/05/19                                           16
ORM – Sequel (Model, 2)
      class Person < Sequel::Model
         has_many :posts, :eager=>[:tags]

           set_schema do
             primary_key :id
             text :name
             text :email
             foreign_key :team_id, :table => :teams
           end

      end

08/05/19                                              17
Evolution




08/05/19               18
Ruby Web Evolution




           Webrick   Mongrel   Event     Thin   Ebb
                               Machine




08/05/19                                              19
Thin ウェブサーバー
 ●   早い – Ragel and Event Machine
 ●   クラスタリング
 ●   Unix sockets - nginx
 ●   Rack-based – Rails, Ramaze etc.
 ●   Rackup ファイルサポート (後で)




08/05/19                               20
Thin + Nginx
           thin start --servers 3 --socket /tmp/thin
           thin start --servers 3 --port 3000
           # nginx.conf
           upstream backend {
             fair;
             server unix:/tmp/thin.0.sock;
             server unix:/tmp/thin.1.sock;
             server unix:/tmp/thin.2.sock;
           }

08/05/19                                               21
問題点


           Merb   Ramaze        Sinatra    ...




                  How to connect them?



           CGI    Webrick      Mongrel    Thin




08/05/19                                         22
ソリューション - Rack


           Merb   Ramaze        Sinatra    ...




                  Rack – The Middle Man




           CGI    Webrick      Mongrel    Thin




08/05/19                                         23
Rackって何?




08/05/19              24
Rackって何なの?

           http://rack.rubyforge.org/




             By Christian Neukirchen
08/05/19                                25
Rackって何?
 ●   HTTPっぽいもののRuby APIのための簡単な仕様
     (とその実装)
       –   Request -> Response
 ●   callメソッドを持ち、envを受け取り以下を返すよう
     なオブジェクト:
       –   a status, i.e. 200
       –   the headers, i.e. {‘Content-Type’ => ‘text/html’}
       –   an object that responds to each: ‘some string’


08/05/19                                                       26
これがRackだ!
      class RackApp
         def call(env)
            [ 200, {quot;Content-Typequot; => quot;text/plainquot;}, quot;Hi!quot;]
         end
      end

      app = RackApp.new




08/05/19                                                      27
Free Hugs




           http://www.freehugscampaign.org/
08/05/19                                      28
Hugs ウェブアプリ (1)




                p 'Hug!'



08/05/19                     29
ruby hugs.rb

           %w(rubygems rack).each { |dep| require dep }

           class HugsApp
              def call(env)
                 [ 200, {quot;Content-Typequot; => quot;text/plainquot;}, quot;Hug!quot;]
              end
           end

           Rack::Handler::Mongrel.run(HugsApp.new, :Port => 3000)




08/05/19                                                            30
Rack::Builder
   require 'hugs'
   app = Rack::Builder.new {
    use Rack::Static, :urls => [quot;/cssquot;, quot;/imagesquot;], :root => quot;publicquot;
    use Rack::CommonLogger
    use Rack::ShowExceptions

       map quot;/quot; do
        run lambda { [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hi!quot;]] }
       end

       map quot;/hugquot; do
        run HugsApp.new
       end
   }

   Rack::Handler::Thin.run app, :Port => 3000

08/05/19                                                                  31
Rack Building Blocks
 ●   request = Rack::Request.new(env)
       –   request.get?
 ●   response = Rack::Response.new('Hi!')
       –   response.set_cookie('sess-id', 'abcde')
 ●   Rack::URLMap
 ●   Rack::Session
 ●   Rack::Auth::Basic
 ●   Rack::File
08/05/19                                             32
Rack Middleware

           自分のuse Rack::「...」 ブロックを作れる?
           class RackMiddlewareExample
            def initialize app
              @app = app
            end

            def call env
              @app.call(env)
            end
           end

08/05/19                                  33
ウェブアプリに必要なこと

 ●   データベースの使い方(ORM): Sequel
 ●   Request手順: Rack::Request(env)
 ●   ルーティング: Rack 'map' and 'run'
 ●   Rendering/views: Tenjin, Amrita2
 ●   Sessions: Rack::Session




08/05/19                                34
Does it scale?



08/05/19                    35
rackup hugs.ru

           require 'hugs'
           app = Rack::Builder.new {
           use Rack::Static, :urls => [quot;/cssquot;, quot;/imagesquot;], :root => quot;publicquot;

           map quot;/quot; do
            run lambda { [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hi!quot;]] }
           end

           map quot;/hugquot; do
             run HugsApp.new
           end
           }
           Rack::Handler::Thin.run app, :Port => 3000


08/05/19                                                                       36
Hugs サービス
 ●   rackup -s webrick -p 3000 hugs.ru
 ●   thin start --servers 3 -p 3000 -R hugs.ru
 ●   SCGI
 ●   FastCGI
 ●   Litespeed
 ●   ....



08/05/19                                         37
Rack-based フレームワークス
 ●   Invisible – thin-based フレームワーク in 35 LOC
       –   http://github.com/macournoyer/invisible/
 ●   Coset – REST on Rack
 ●   Halcyon – JSON Server Framework
 ●   Merb
 ●   Sinatra
 ●   Ramaze
 ●   Rails !?
08/05/19                                              38
RailsにもRackが必要
 ●   RailsはRackをすでに持っている、しかし:
       –   raw req -> rack env -> Rack::Request ->CGIWrapper ->
           CgiRequest
 ●   Ezra Zygmuntowicz (merb)'s repo on github
       –   http://github.com/ezmobius/rails
       –   raw req -> rack env -> ActionController::RackRequest
       –   ./script/rackup -s thin -c 5 -e production




08/05/19                                                          39
Ramaze
 ●   何?: モジュラーウェブアプリ フレームワーク
 ●   どこで?: http://ramaze.net/
 ●   どうやって?: gem install ramaze
 ●   git clone http://github.com/manveru/ramaze.git
 ●   誰が?: Michael Fellinger and Co.




08/05/19                                              40
なぜ Ramaze?
 ●   モジュラー (low [loosely] coupling)
 ●   Rack-based
 ●   簡単な使い方
 ●   たくさんの例 (~25) – facebook, rapaste
 ●   フリースタイルな開発
 ●   フレンドリーなコミュ - #ramaze
 ●   “All bugs are fixed within 48 hours of reporting.”

08/05/19                                              41
Deployment オプションズ
           ●   CGI         ●   Ebb
           ●   FastCGI     ●   Evented Mongrel
           ●   LiteSpeed   ●   Swiftiplied Mongrel
           ●   Mongrel     ●   Thin
           ●   SCGI        ●   Rack-basedなら使える
           ●   Webrick



08/05/19                                             42
Templating engines
           ●   Amrita2     ●   RedCloth
           ●   Builder     ●   Remarkably
           ●   Erubis      ●   Sass
           ●   Ezamar      ●   Tagz
           ●   Haml        ●   Tenjin
           ●   Liquid      ●   XSLT
           ●   Markaby

08/05/19                                    43
Ezamar




08/05/19            44
本当に簡単?

           %w(rubygems ramaze).each {|dep| require dep}

           class MainController < Ramaze::Controller
             def index; quot;Hiquot; end
           end

           class HugsController < Ramaze::Controller
             map '/hug'
             def index; quot;Hug!quot; end
           end

           Ramaze.start :adapter => :thin, :port => 3000


08/05/19                                                   45
Ramaze使い方
           class SmileyController < Ramaze::Controller
              map '/smile'

             helper :smiley

             def index
               smiley(':)')
             end
           end




08/05/19                                                 46
Ramaze 使い方 (2)
           module Ramaze
             module Helper
               module SmileyHelper
                  FACES = {
                   ':)' => '/images/smile.png',
                   ';)' => '/images/twink.png'}
                  REGEXP = Regexp.union(*FACES.keys)

                  def smiley(string)
                    string.gsub(REGEXP) { FACES[$1] }
                  end
                end
             end
           end

08/05/19                                                47
他のStack
 ●   ORM – Sequel
 ●   ウェブサーバー – Thin + NginX
 ●   Rack Middleware
 ●   Ramaze フレームワーク
 ●   Templates – HAML, Tenjin, Amrita2




08/05/19                                 48
まとめ
 ●   Railsを使うなとは言いません
 ●   オープンマインドで
 ●   SequelはORMに適している
 ●   Rackを使え! – DIY framework, DIY server
 ●   Ramazeはかっこよくて、使いやすい!




08/05/19                                    49

More Related Content

What's hot

Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Rails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on RailsRails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on RailsDonSchado
 
ChefConf 2012 Spiceweasel
ChefConf 2012 SpiceweaselChefConf 2012 Spiceweasel
ChefConf 2012 SpiceweaselMatt Ray
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
The DOM is a Mess @ Yahoo
The DOM is a Mess @ YahooThe DOM is a Mess @ Yahoo
The DOM is a Mess @ Yahoojeresig
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop AftermathDenis Zhdanov
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsRemy Sharp
 
Five Pound App talk: hereit.is, Web app architecture, REST, CSS3
Five Pound App talk: hereit.is, Web app architecture, REST, CSS3Five Pound App talk: hereit.is, Web app architecture, REST, CSS3
Five Pound App talk: hereit.is, Web app architecture, REST, CSS3Jamie Matthews
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015Jeongkyu Shin
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientAdam Wiggins
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudHiro Asari
 
You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...
You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...
You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...Rencore
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 

What's hot (20)

Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Rails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on RailsRails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on Rails
 
ChefConf 2012 Spiceweasel
ChefConf 2012 SpiceweaselChefConf 2012 Spiceweasel
ChefConf 2012 Spiceweasel
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
The DOM is a Mess @ Yahoo
The DOM is a Mess @ YahooThe DOM is a Mess @ Yahoo
The DOM is a Mess @ Yahoo
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop Aftermath
 
Vidoop CouchDB Talk
Vidoop CouchDB TalkVidoop CouchDB Talk
Vidoop CouchDB Talk
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Five Pound App talk: hereit.is, Web app architecture, REST, CSS3
Five Pound App talk: hereit.is, Web app architecture, REST, CSS3Five Pound App talk: hereit.is, Web app architecture, REST, CSS3
Five Pound App talk: hereit.is, Web app architecture, REST, CSS3
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the Cloud
 
You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...
You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...
You don’t know JS about SharePoint - Mastering javascript performance (Hugh W...
 
All That Jazz
All  That  JazzAll  That  Jazz
All That Jazz
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
WordPress APIs
WordPress APIsWordPress APIs
WordPress APIs
 

Similar to Ruby off Rails (japanese)

Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)Stoyan Zhekov
 
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909Yusuke Wada
 
Rails Deployment with NginX
Rails Deployment with NginXRails Deployment with NginX
Rails Deployment with NginXStoyan Zhekov
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhereelliando dias
 
Transfer to kubernetes data platform from EMR
Transfer to kubernetes data platform from EMRTransfer to kubernetes data platform from EMR
Transfer to kubernetes data platform from EMR창언 정
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102APNIC
 
Wide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service BackendWide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service BackendMySQLConference
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
RubyScraping
RubyScrapingRubyScraping
RubyScrapingyhara
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
yet another rails
yet another railsyet another rails
yet another railsashok kumar
 
Scaling Rails Presentation
Scaling Rails PresentationScaling Rails Presentation
Scaling Rails Presentationeraz
 

Similar to Ruby off Rails (japanese) (20)

Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)
 
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
 
Rails Deployment with NginX
Rails Deployment with NginXRails Deployment with NginX
Rails Deployment with NginX
 
XS Japan 2008 Xen Mgmt Japanese
XS Japan 2008 Xen Mgmt JapaneseXS Japan 2008 Xen Mgmt Japanese
XS Japan 2008 Xen Mgmt Japanese
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Sinatra
SinatraSinatra
Sinatra
 
JSON Viewer XPATH Workbook
JSON Viewer XPATH WorkbookJSON Viewer XPATH Workbook
JSON Viewer XPATH Workbook
 
Transfer to kubernetes data platform from EMR
Transfer to kubernetes data platform from EMRTransfer to kubernetes data platform from EMR
Transfer to kubernetes data platform from EMR
 
Sinatra
SinatraSinatra
Sinatra
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
rails-footnotes
rails-footnotesrails-footnotes
rails-footnotes
 
Wide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service BackendWide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service Backend
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
RubyScraping
RubyScrapingRubyScraping
RubyScraping
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Jvm Language Summit Rose 20081016
Jvm Language Summit Rose 20081016Jvm Language Summit Rose 20081016
Jvm Language Summit Rose 20081016
 
yet another rails
yet another railsyet another rails
yet another rails
 
Scaling Scribd
Scaling ScribdScaling Scribd
Scaling Scribd
 
Scaling Rails Presentation
Scaling Rails PresentationScaling Rails Presentation
Scaling Rails Presentation
 

More from Stoyan Zhekov

Padrino - the Godfather of Sinatra
Padrino - the Godfather of SinatraPadrino - the Godfather of Sinatra
Padrino - the Godfather of SinatraStoyan Zhekov
 
Deployment on Heroku
Deployment on HerokuDeployment on Heroku
Deployment on HerokuStoyan Zhekov
 
Push the web with HTML5
Push the web with HTML5Push the web with HTML5
Push the web with HTML5Stoyan Zhekov
 
Foreman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple componentsForeman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple componentsStoyan Zhekov
 
Social Network for spare parts
Social Network for spare partsSocial Network for spare parts
Social Network for spare partsStoyan Zhekov
 
Using XMPP Presence stanzas for real-time parking information
Using XMPP Presence stanzas for real-time parking informationUsing XMPP Presence stanzas for real-time parking information
Using XMPP Presence stanzas for real-time parking informationStoyan Zhekov
 
Websockets with ruby
Websockets with rubyWebsockets with ruby
Websockets with rubyStoyan Zhekov
 
Webhooks - glue for the web (japanese)
Webhooks - glue for the web (japanese)Webhooks - glue for the web (japanese)
Webhooks - glue for the web (japanese)Stoyan Zhekov
 
Webhooks - glue for the web
Webhooks - glue for the webWebhooks - glue for the web
Webhooks - glue for the webStoyan Zhekov
 
Microblogging via XMPP (japanese)
Microblogging via XMPP (japanese)Microblogging via XMPP (japanese)
Microblogging via XMPP (japanese)Stoyan Zhekov
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPPStoyan Zhekov
 

More from Stoyan Zhekov (16)

Multirotors
MultirotorsMultirotors
Multirotors
 
ZeroMQ
ZeroMQZeroMQ
ZeroMQ
 
Padrino - the Godfather of Sinatra
Padrino - the Godfather of SinatraPadrino - the Godfather of Sinatra
Padrino - the Godfather of Sinatra
 
Sequel
SequelSequel
Sequel
 
Deployment on Heroku
Deployment on HerokuDeployment on Heroku
Deployment on Heroku
 
Push the web with HTML5
Push the web with HTML5Push the web with HTML5
Push the web with HTML5
 
Foreman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple componentsForeman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple components
 
Social Network for spare parts
Social Network for spare partsSocial Network for spare parts
Social Network for spare parts
 
Using XMPP Presence stanzas for real-time parking information
Using XMPP Presence stanzas for real-time parking informationUsing XMPP Presence stanzas for real-time parking information
Using XMPP Presence stanzas for real-time parking information
 
Ruby cooking
Ruby cookingRuby cooking
Ruby cooking
 
Websockets with ruby
Websockets with rubyWebsockets with ruby
Websockets with ruby
 
EventMachine
EventMachineEventMachine
EventMachine
 
Webhooks - glue for the web (japanese)
Webhooks - glue for the web (japanese)Webhooks - glue for the web (japanese)
Webhooks - glue for the web (japanese)
 
Webhooks - glue for the web
Webhooks - glue for the webWebhooks - glue for the web
Webhooks - glue for the web
 
Microblogging via XMPP (japanese)
Microblogging via XMPP (japanese)Microblogging via XMPP (japanese)
Microblogging via XMPP (japanese)
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPP
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Ruby off Rails (japanese)

  • 1. Ruby off Rails by Stoyan Zhekov Kyoto, 17-May-2008
  • 2. 自己紹介 ● 名前: ストヤン ジェコフ ● ブルガリア人 ● 3人男の子のパパ
  • 3. 内容 ● Coupling and Cohesion ● ウェブアプリに必要なこと ● ORM - Sequel (簡単な見解) ● Ruby ウェブエボリューション ● Enter Rack - The Middle Man ● Thin, Ramaze, Tamanegi ● まとめ, その他, 質問 08/05/19 3
  • 4. Coupling and Cohesion (1) ● Cohesion - 凝集度 (ぎょうしゅうど) http://en.wikipedia.org/wiki/Cohesion_(computer_science) ● Coupling - 結合度 (けつごうど) http://en.wikipedia.org/wiki/Coupling_(computer_science) 08/05/19 4
  • 5. Coupling and Cohesion (2) 正しいウェブアプリの組み立て方 ● High cohesion – 少ない動作でたかい機能性 ● Low (loosely) coupling – 簡単な入れ替え 08/05/19 5
  • 6. Coupling and Cohesion (3) Google vs Amazon 08/05/19 6
  • 7. Coupling and Cohesion (5) VS 08/05/19 7
  • 9. Ruby on Rails ● 全部セットでよかった。しかし、今は? ● Convention over configuration – いいのか? ● DRY – 可能? – Generators – Plugins – Libraries 08/05/19 9
  • 10. Railsなしの人生 できる? 08/05/19 10
  • 11. ウェブアプリに必要なこと ● データベースの使い方: ORM ● Request手順: CGI env, アップロード ● ルーティング: URLとクラスの組み合わせ ● Rendering (views): rendering libraries ● Sessions: persist objects or data 08/05/19 11
  • 12. Database ORM ● Active Record ?= ActiveRecord ● ActiveRecord – たくさんの問題点 – http://datamapper.org/why.html ● Data Mapper – 早いけどまだ未完 – まだコンポジットキーなし – 自分のDBドライバーが必要 ● Sequel – よし。気に入ってる。 08/05/19 12
  • 13. ORM – Sequel (なぜ?) ● Pure Ruby ● Thread safe ● Connection pooling ● DB queries構築のためのDSL ● ObjectとDBレコードの組み合わせの軽いORM ● Transactions with rollback 08/05/19 13
  • 14. ORM – Sequel (Core) ● データベースのつなげ方 require 'sequel' DB = Sequel.open 'sqlite:///blog.db' DB = Sequel.open 'postgres://cico:12345@localhost:5432/mydb' DB = Sequel.open(quot;postgres://postgres:postgres@localhost/my_dbquot;, :max_connections => 10, :logger => Logger.new('log/db.log')) 08/05/19 14
  • 15. ORM – Sequel (Core, 2) DB << quot;CREATE TABLE users (name VARCHAR(255) NOT NULL)quot; DB.fetch(quot;SELECT name FROM usersquot;) do |row| p r[:name] end dataset = DB[:managers].where(:salary => 50..100).order(:name, :department) paginated = dataset.paginate(1, 10) # first page, 10 rows per page paginated.page_count #=> number of pages in dataset paginated.current_page #=> 1 08/05/19 15
  • 16. ORM – Sequel (Model) class Post < Sequel::Model(:my_posts) set_primary_key [:category, :title] belongs_to :author has_many :comments has_and_belongs_to_many :tags after_create do set(:created_at => Time.now) end end 08/05/19 16
  • 17. ORM – Sequel (Model, 2) class Person < Sequel::Model has_many :posts, :eager=>[:tags] set_schema do primary_key :id text :name text :email foreign_key :team_id, :table => :teams end end 08/05/19 17
  • 19. Ruby Web Evolution Webrick Mongrel Event Thin Ebb Machine 08/05/19 19
  • 20. Thin ウェブサーバー ● 早い – Ragel and Event Machine ● クラスタリング ● Unix sockets - nginx ● Rack-based – Rails, Ramaze etc. ● Rackup ファイルサポート (後で) 08/05/19 20
  • 21. Thin + Nginx thin start --servers 3 --socket /tmp/thin thin start --servers 3 --port 3000 # nginx.conf upstream backend { fair; server unix:/tmp/thin.0.sock; server unix:/tmp/thin.1.sock; server unix:/tmp/thin.2.sock; } 08/05/19 21
  • 22. 問題点 Merb Ramaze Sinatra ... How to connect them? CGI Webrick Mongrel Thin 08/05/19 22
  • 23. ソリューション - Rack Merb Ramaze Sinatra ... Rack – The Middle Man CGI Webrick Mongrel Thin 08/05/19 23
  • 25. Rackって何なの? http://rack.rubyforge.org/ By Christian Neukirchen 08/05/19 25
  • 26. Rackって何? ● HTTPっぽいもののRuby APIのための簡単な仕様 (とその実装) – Request -> Response ● callメソッドを持ち、envを受け取り以下を返すよう なオブジェクト: – a status, i.e. 200 – the headers, i.e. {‘Content-Type’ => ‘text/html’} – an object that responds to each: ‘some string’ 08/05/19 26
  • 27. これがRackだ! class RackApp def call(env) [ 200, {quot;Content-Typequot; => quot;text/plainquot;}, quot;Hi!quot;] end end app = RackApp.new 08/05/19 27
  • 28. Free Hugs http://www.freehugscampaign.org/ 08/05/19 28
  • 29. Hugs ウェブアプリ (1) p 'Hug!' 08/05/19 29
  • 30. ruby hugs.rb %w(rubygems rack).each { |dep| require dep } class HugsApp def call(env) [ 200, {quot;Content-Typequot; => quot;text/plainquot;}, quot;Hug!quot;] end end Rack::Handler::Mongrel.run(HugsApp.new, :Port => 3000) 08/05/19 30
  • 31. Rack::Builder require 'hugs' app = Rack::Builder.new { use Rack::Static, :urls => [quot;/cssquot;, quot;/imagesquot;], :root => quot;publicquot; use Rack::CommonLogger use Rack::ShowExceptions map quot;/quot; do run lambda { [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hi!quot;]] } end map quot;/hugquot; do run HugsApp.new end } Rack::Handler::Thin.run app, :Port => 3000 08/05/19 31
  • 32. Rack Building Blocks ● request = Rack::Request.new(env) – request.get? ● response = Rack::Response.new('Hi!') – response.set_cookie('sess-id', 'abcde') ● Rack::URLMap ● Rack::Session ● Rack::Auth::Basic ● Rack::File 08/05/19 32
  • 33. Rack Middleware 自分のuse Rack::「...」 ブロックを作れる? class RackMiddlewareExample def initialize app @app = app end def call env @app.call(env) end end 08/05/19 33
  • 34. ウェブアプリに必要なこと ● データベースの使い方(ORM): Sequel ● Request手順: Rack::Request(env) ● ルーティング: Rack 'map' and 'run' ● Rendering/views: Tenjin, Amrita2 ● Sessions: Rack::Session 08/05/19 34
  • 36. rackup hugs.ru require 'hugs' app = Rack::Builder.new { use Rack::Static, :urls => [quot;/cssquot;, quot;/imagesquot;], :root => quot;publicquot; map quot;/quot; do run lambda { [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hi!quot;]] } end map quot;/hugquot; do run HugsApp.new end } Rack::Handler::Thin.run app, :Port => 3000 08/05/19 36
  • 37. Hugs サービス ● rackup -s webrick -p 3000 hugs.ru ● thin start --servers 3 -p 3000 -R hugs.ru ● SCGI ● FastCGI ● Litespeed ● .... 08/05/19 37
  • 38. Rack-based フレームワークス ● Invisible – thin-based フレームワーク in 35 LOC – http://github.com/macournoyer/invisible/ ● Coset – REST on Rack ● Halcyon – JSON Server Framework ● Merb ● Sinatra ● Ramaze ● Rails !? 08/05/19 38
  • 39. RailsにもRackが必要 ● RailsはRackをすでに持っている、しかし: – raw req -> rack env -> Rack::Request ->CGIWrapper -> CgiRequest ● Ezra Zygmuntowicz (merb)'s repo on github – http://github.com/ezmobius/rails – raw req -> rack env -> ActionController::RackRequest – ./script/rackup -s thin -c 5 -e production 08/05/19 39
  • 40. Ramaze ● 何?: モジュラーウェブアプリ フレームワーク ● どこで?: http://ramaze.net/ ● どうやって?: gem install ramaze ● git clone http://github.com/manveru/ramaze.git ● 誰が?: Michael Fellinger and Co. 08/05/19 40
  • 41. なぜ Ramaze? ● モジュラー (low [loosely] coupling) ● Rack-based ● 簡単な使い方 ● たくさんの例 (~25) – facebook, rapaste ● フリースタイルな開発 ● フレンドリーなコミュ - #ramaze ● “All bugs are fixed within 48 hours of reporting.” 08/05/19 41
  • 42. Deployment オプションズ ● CGI ● Ebb ● FastCGI ● Evented Mongrel ● LiteSpeed ● Swiftiplied Mongrel ● Mongrel ● Thin ● SCGI ● Rack-basedなら使える ● Webrick 08/05/19 42
  • 43. Templating engines ● Amrita2 ● RedCloth ● Builder ● Remarkably ● Erubis ● Sass ● Ezamar ● Tagz ● Haml ● Tenjin ● Liquid ● XSLT ● Markaby 08/05/19 43
  • 45. 本当に簡単? %w(rubygems ramaze).each {|dep| require dep} class MainController < Ramaze::Controller def index; quot;Hiquot; end end class HugsController < Ramaze::Controller map '/hug' def index; quot;Hug!quot; end end Ramaze.start :adapter => :thin, :port => 3000 08/05/19 45
  • 46. Ramaze使い方 class SmileyController < Ramaze::Controller map '/smile' helper :smiley def index smiley(':)') end end 08/05/19 46
  • 47. Ramaze 使い方 (2) module Ramaze module Helper module SmileyHelper FACES = { ':)' => '/images/smile.png', ';)' => '/images/twink.png'} REGEXP = Regexp.union(*FACES.keys) def smiley(string) string.gsub(REGEXP) { FACES[$1] } end end end end 08/05/19 47
  • 48. 他のStack ● ORM – Sequel ● ウェブサーバー – Thin + NginX ● Rack Middleware ● Ramaze フレームワーク ● Templates – HAML, Tenjin, Amrita2 08/05/19 48
  • 49. まとめ ● Railsを使うなとは言いません ● オープンマインドで ● SequelはORMに適している ● Rackを使え! – DIY framework, DIY server ● Ramazeはかっこよくて、使いやすい! 08/05/19 49