Ruby会議2009 #1 (2009/07/17)
まとめと感想
開会の言葉
- 高橋さんによる開会の言葉
- 4回目
- 3日間
- 3セッション同時並行
- スポンサーのご紹介
- 中継をどこかでやるらしい
- 中会議場,特別会議室などには電源がある
Using Git and GitHub to Develope One Millon Times Faster
- Scott Chacon from github.com
- http://git-scm.com/ の人
- Pro git http://progit.org/
What is git
- Snapshot, not patch
- branche is pointer to a commit.
- merging -> create a new commit which parent is default and experimental
- 3 hot way(?)
- Save individual time
- No network needed
- frictionless context switching <- branching
- non-linear development
- create new branches, switching between branches and development
- branching as a patch queue
- ブランチを作ることでパッチを作成できる.キューっぽく
- fork queue on github. queue!
- git rebase/format-path/am
- non-linear development
- git rebase -> make patches
- commit 間の patch をスタックして,rebase 先の commit に適用する感じ
- git rebase --onto master server
- branch of branch の時に,親の親に rebase できないのを,onto で指定する感じ
- squash
- commit message を1つにまとめる
- Save team time
- integration manager をおいて管理する
- dictator/l...
Pragmatic Patterns of Ruby on Rails
conding patterns with RoR
- 実装パターン
- ターゲット
- large and complicated
- team building
- Problems of large applications
- coding style
- coding quality
- メンテしにくくなる
- いいコードを書く必要がある
- いい設計,読みやすい,わかりやすい,間違いにすぐ気づく
- そこでパターン
- 共通パターンを作る
- 控えめに DSL を使う
- このプレゼンで触れないこと
- パフォーマンスの追求
- ActiveRecord
- 実例紹介#1
- 権限のあるデータを表示(show permitted data)
- パターン#1
- 普通に検索する
- find_by_id_and_user_id
- written_by(user_id).find(:id)
- named_scope
- これらは条件を忘れても気づきにくい
- オブジェクト起点で検索
- current_user.notes.find(:id)
- 文脈でわかる
- current_user.notes.find(:id)
- Filter で書く
- controller の filter で書く
- @group = ... を before_filter で処理しておく
- conding style に自然な強制力が働く
- ちゃんと名前をつけることで,わかりやすくできる
- controller の filter で書く
- 普通に検索する
- 実例紹介#2
「エンタープライズRails」に学ぶ企業ユーザのためのRailsアーキテクチャ
前振り
データベースの制約を活用する
複合主キーを導入する
- has_many だと無駄な JOIN が発生してしまう
- 望ましいのは,Employees に company_id を入れた感じ
- ただしこれだとアプリケーションレベルでの制約しかなくなる
- そこで Departments に複合主キーを作る
- Employees にかならず Companies/Departments の組み合わせのキーが入るので,存在しない Companies/Departments の組み合わせを取得することができない
- Rails 側で導入するには
- # gem install composite_primary_key
- 中間テーブルを複合主キー化する
- 子テーブルに親の親の主キーと親の主キーへの外部参照を設定する
ビューでシンプルにする
- 複数のテーブルからの,複雑な検索条件を問い合わせたい
- ビューを作って,モデルも作れば参照できる
- view-backed model と言うらしい
- ビューはサブクエリみたいに使える
Q&A
- migration では制約はどう書く?
- execute で書く
- エンタープライジーな人は migration なんて使わない
- ビューは使えるのか?
- view-backed model は使える
- パフォーマンスの問題はある
- 使いどころを見極める
- view-backed model は使える
- composite_primary_key は最新の Rails で使えるの?
- forum 見ようね
- AR の代替は書いてる?AR は好き?
- 代替は書いてない
- AR は好きというか,流されてる?
- memcached とかどう?
- materialized view の涙ぐましい努力を見ようね
- (キャッシュのレベルが違う?)
- materialized view の涙ぐましい努力を見ようね
- 複合主キーの良い例は書いてる?
- 複雑な例が書いてある
- Web の人に呼んで欲しい
- 原書 PDF で読もうかな
より良きruby市民のために Rails 3
- Better Ruby Citizen
- @wycats Yefuda Katz from EngineYard
- merb + Rails -> Rails 3
- EngineYard
- Solo
- Flex
- Rails 3
- Rack
- JSON
- Erubis
- More love
- Rails 3 have special API
- for DataMapper
- for jQuery
- for CouchRest
- ActiveModel
- = ActiveRecord - DatabaseAdapter
- ex)
- include ActiveModel::Validations
- use valdations like ActiveRecord
- include ActiveModel::Validations
- Components
- API
- extend ActiveModel::Naming
- person_path(@person) works fine in controllers
- form_for/error_messages works fine too in views
- extend ActiveModel::Naming
- API
- Decoupled
- ActiveRecord + ActionController + ActionView = Rails 2.3
- three classes are mutually combined
- Rails 3 = ActionController + ActionView + ActiveModel
- ActiveRecord + ActionController + ActionView = Rails 2.3
- ActionPack
-
- ActionContoller::Http
- Metal in Rails 2.3?
- ActionContoller::Http
- Simple
-
-
- Kaigi.action(:index) returns ActionController::Http object.
-
-
- Callbacks
- include AbstractController::Callbakcs
- uses callbacks like ActionController::Base
- include AbstractController::Callbakcs
- Render
- include ActionController::Renderer
- uses render :template => "..." like ActionController::Base
- include ActionController::Renderer
- Layouts
- include ActionController::Layouts
- uses layout "..." like ActionController::Base
- include ActionController::Layouts
-
- ActiveSupport
- Less Pollution
- Cherry Pick
- Manage Modules
- ActiveSupport::Concern
- included?
- ActiveSupport::Concern
- Isolation Testing
- include ActiveSupport:::Testing::Isolation
- each test processes run in different enveioments
- include ActiveSupport:::Testing::Isolation
Summary
- 劇的な変更があるが,これにあわせてシステムを書き換えるのはかなり大変そう
- まあ一部の機能しか使わなければ,特に問題にはならないのかも知れないが
Q&A
- Plugin はどうかわる?
- API を定義するからこれで最後の変更になる
- こっからがんばってくれ
Lightning Talks
- あとで写真アップ予定
- KeyValue Store な話が複数あったのは,時代の流れだろうか.
- レガシー = P** な話が一番おもしろかった