SlideShare a Scribd company logo
1 of 41
相依性管理
 以Ruby開發為例

大貓 (@miaout17)
About Me
• 大貓 (YC Ling, @miaout17)
• 2004年因為奇妙的機緣開始學習Ruby
 – RPG Maker XP
 – Rails? 能吃嗎?
About Me
•   大貓 (YC Ling, @miaout17)
•   業餘Ruby遊戲開發者(2004~2007)
•   C++/Lua/ActionScript遊戲開發者(2007~2010)
•   Java/Ruby Web開發者(2010~now)
•   業餘Functional Programming愛好者
•   Github: https://github.com/miaout17
這場分享
• 不是來傳Ruby教的
• 沒什麼Ruby程式碼,不會Ruby也能聽懂

• 分享我對「高階語言相依性管理」的想法
 – Ruby開發流程很方便
 – 自Ruby開發流程抽取與語言無關的概念
Top 10 Programmer Excuses




 Google: 2011 COSCUP Lightning Talk 嵌入式開發的故事
Top 10 Programmer WTF
相依性!
高階語言開發的相依性
                               Applications

How can we make
                                 Libraries
it more smooth?

                    Virtual Machine/Interpreter/Compiler

   Abstraction!
                         Native Code / Libraries
Write once, debug
run anywhere                        OS

                                Hardware
High-Level Languages Development
          in 2012 should…
1. 容易安裝、切換執行環境
2. 容易安裝函式庫
3. 確保所有開發者、部署環境使用相同版本
   的函式庫
4. 使用版本控制系統,程式化地管理相依性
5. 函式庫應使用一致的版號規則描述相容性
“Getting Started” Scenario

                    Install environment



                     Clone the project


                      Install project
                      dependencies



  Run the program    Execute unit test


                                         TDD
安裝 Ruby Rubies
                                        Install environment

$ apt-get install ruby
$ yum –y install ruby                    Clone the project


                                          Install project
• Not always up-to-date                   dependencies

• Always not up-to-date
• Multiple Rubies: MRI                   Execute unit test

  1.8.7, 1.9.2, 1.9.3, REE, JRuby, Ru                        TDD
  binius, IronRuby, MacRuby, …
RVM (Ruby Version Manager)
安裝RVM                                            Install environment

$ curl -L get.rvm.io | bash -s stable
                                                  Clone the project
安裝Rubies
$ rvm install 1.8.7
                                                   Install project
$ rvm install 1.9.3-p125                           dependencies
$ rvm install jruby
切換不同Rubies                                        Execute unit test
$ rvm use 1.8.7
$ rvm use 1.9.3 --default                                             TDD


                        See Also: PerlBrew, PythonBrew, PHPBrew…
.rvmrc
提醒您使用正確的Ruby環境
安裝環境
$ rvm install 1.9.3          Install environment



                              Clone the project


                               Install project
                               dependencies



                              Execute unit test


                                                  TDD
下載專案源始碼
                                               Install environment



$ git clone git://github.com/rails/rails.git    Clone the project


                                                 Install project
                                                 dependencies



                                                Execute unit test


                                                                    TDD
Library Management in Ruby
• 主流工具:                          Install environment

 – RubyGems: 管理Ruby套件
 – Bundler: 管理Application與Gem的    Clone the project
   相依性
                                   Install project
                                   dependencies



                                  Execute unit test


                                                      TDD
RubyGems
安裝gem及其相依的gems
$ gem install rails
$ gem install rails –v=2.3.5
更新gems
$ gem update
發佈gems
$ gem push foo-1.0.0.gem


          Yes. A lot of languages can do this.
          See Also: pip, cpan, pear, onion, cabal, npm, maven, ivy…
Gemspec
Gem 相依性
固定版本
                                                                   Devise
s.add_dependency ’devise', ‘1.5.0'                                  2.0.0

最小版本                                                     Broken!
                                                                   Devise
s.add_dependency ’devise', ‘>= 1.5.0'                               1.6.0
版本範圍
                                                   Library         Devise
s.add_dependency ’devise', ‘>= 1.5’, ‘< 2.0’       Foobar           1.5.0

“Twiddle Wakka”
s.add_dependency ’devise', ‘~> 1.5’      # ‘>= 1.5’, ‘< 2.0’
s.add_dependency ’devise', ‘~> 1.5.1’    # ‘>=1.5.1’, ‘< 1.6’

            Just a shortcut?
Semantic Versioning
• Authored by Tom Preston-Werner, inventor of
  Gravatars and cofounder of GitHub
• 一致的版號規則: Major.Minor.Patch
• Rails 3.1.10
  – Major version: 3
  – Minor version: 1
  – Patch version: 10
Semantic Versioning
• Major version change
  – 不向下相容
  – Ex. Rails 2.3.7 -> 3.0.0
• Minor version change
  – 向下相容,增加新功能
  – Ex. Rails 3.0.10 -> 3.1.0
• Patch version change
  – 向下相容,只修正bug
  – Ex. Rails 3.1.0 -> 3.1.1
Semantic Versioning
• 例外: Major version 0為早期開發
  – 0.0.1, 0.0.2, 0.9.4 什麼都可能不相容
• 更多細節請見 http://semver.org/
  – Pre-release
  – Tag name
  – Semantic versioning v2.0.0-rc1
• See also: Apache APR Version Numbering
Semantic Versioning
 • Semantic Version + Twiddle Wakka
     – 使用一致的版號規則描述相容性
     – 簡潔地指定「相容的版本區間」
s.add_dependency ’devise', ‘~> 1.5’     # ‘>= 1.5’, ‘< 2.0’
s.add_dependency ’devise', ‘~> 1.5.0’   # ‘>=1.5.0’, ‘< 1.6’

 • Encouraged by the Ruby community
     – http://robots.thoughtbot.com/post/2508037841/twiddle-wakka
     – http://www.slideshare.net/copiousfreetime/gemology
     – 許多專案Follow此規則
為什麼需要Bundler?
                          Installed Gems


                                       Rails
                Broken!
                                       3.0.0



Execute with       Rails              Sqlite3
                                                Execute with
                   2.3.7               1.3.3
  Bundler                                         Bundler
    Project                                       Project
     Alala         Devise                         Wahaha
                    2.0.0


                              JSON
                              1.2.1
Gem v.s. Bundler
• Gem
  – 安裝/反安裝/發佈gem
  – Gemspec管理gem與gem的相依性
• Bundler
  – 管理application與gem的相依性
     • 幫你把application需要的gem一次全部裝好
     • 確保所有開發者及部署使用相同版本的gem
  – 題外話:bundler也能拿來開發gem
Bundler
在Gemfile中設定相依性




       See Also: gradle, maven, ivy, sbt, virtualenv, carton
Bundler
               bundle install
執行`bundle install`:
1. 計算並安裝所需要的gem
2. 產生 “Gemfile.lock”
Gemfile.lock
Bundler
       Ensure you are using right gems
在Shell中執行:
$ bunlde exec ruby your_app.rb

或是在程式啟始點:

require "rubygems"
require "bundler/setup"

建議:所有的Ruby專案都可以使用Bundler
Bundler with git
修改Gemfile
$ vim Gemfile
$ bundle install # or bundle update
$ git add Gemfile Gemfile.lock; git commit

更新Gems
 $ bundle update
 $ git add Gemfile.lock; git commit
安裝相依之函式庫
                          Install environment



                           Clone the project


                            Install project
$ bundle install            dependencies



                           Execute unit test


                                               TDD
執行單元測試…
              使用正確版本的函式庫
                          Install environment



                           Clone the project


                            Install project
                            dependencies



$ bundle exec rake test    Execute unit test


                                               TDD
Wrapping up
$ rvm install 1.9.3-p125                       Install environment



$ git clone git://github.com/rails/rails.git    Clone the project



$ cd rails                                       Install project
                                                 dependencies
$ bundle install

$ bundle exec rake test                         Execute unit test


                                                                    TDD
結論
High-Level Languages Development
          in 2012 should…
1. 容易安裝、切換執行環境
2. 容易安裝函式庫
3. 確保所有開發者、部署環境使用相同版本
   的函式庫
4. 使用版本控制系統,程式化地管理相依性
5. 函式庫應使用一致的版號規則描述相容性
這些概念與語言無關
PHPBrew, Onion


https://github.com/c9s/phpbrew
Brew & manage PHP versions in pure
PHP at HOME
https://github.com/c9s/Onion
Onion, The fast approach to
build/bundle PEAR packages for PHP.
Carton

Carton is a new command to manage Perl
module dependencies for your applications.
Like gem bundler for Ruby, Carton solves the
issue of "upgrading CPAN modules broke my
code" by allowing you to lock and freeze
dependencies. Carton makes it easy to
manage and reproduce module installations
on any environments.
不要走開,接下來是iHower大大精彩的分享
「那些Functional Programming教我的事」


         Any Question?

More Related Content

What's hot

前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧Chu-Siang Lai
 
docker intro
docker introdocker intro
docker introkoji lin
 
Docker tutorial
Docker tutorialDocker tutorial
Docker tutorialazole Lai
 
Docker 最佳实践
Docker 最佳实践Docker 最佳实践
Docker 最佳实践YuLing Liu
 
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIContinuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIChu-Siang Lai
 
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)Will Huang
 
Asp.net mvc 6 新功能初探
Asp.net mvc 6 新功能初探Asp.net mvc 6 新功能初探
Asp.net mvc 6 新功能初探Gelis Wu
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIChu-Siang Lai
 
Maven初级培训
Maven初级培训Maven初级培训
Maven初级培训Cody Zhang
 
Asp.net 5 新功能與變革
Asp.net 5 新功能與變革Asp.net 5 新功能與變革
Asp.net 5 新功能與變革Gelis Wu
 
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018Will Huang
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Miles Chou
 
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated企業導入微服務實戰 - updated
企業導入微服務實戰 - updatedPaul Chao
 
20150604 docker 新手入門
20150604 docker 新手入門20150604 docker 新手入門
20150604 docker 新手入門azole Lai
 

What's hot (20)

前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧
 
docker intro
docker introdocker intro
docker intro
 
Docker基礎
Docker基礎Docker基礎
Docker基礎
 
Docker tutorial
Docker tutorialDocker tutorial
Docker tutorial
 
Docker 最佳实践
Docker 最佳实践Docker 最佳实践
Docker 最佳实践
 
Docker應用
Docker應用Docker應用
Docker應用
 
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIContinuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CI
 
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)
 
Asp.net mvc 6 新功能初探
Asp.net mvc 6 新功能初探Asp.net mvc 6 新功能初探
Asp.net mvc 6 新功能初探
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CI
 
Docker Build
Docker BuildDocker Build
Docker Build
 
Maven初级培训
Maven初级培训Maven初级培训
Maven初级培训
 
Vagrant教學
Vagrant教學Vagrant教學
Vagrant教學
 
Asp.net 5 新功能與變革
Asp.net 5 新功能與變革Asp.net 5 新功能與變革
Asp.net 5 新功能與變革
 
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
開發人員必須知道的 Kubernetes 核心技術 - Kubernetes Summit 2018
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
 
Ansible 101
Ansible 101Ansible 101
Ansible 101
 
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
 
20150604 docker 新手入門
20150604 docker 新手入門20150604 docker 新手入門
20150604 docker 新手入門
 
Docker
DockerDocker
Docker
 

Similar to [OSDC12]相依性管理 - 以Ruby開發為例

Maven初级培训
Maven初级培训Maven初级培训
Maven初级培训ytsolar
 
Rubyonrails(Chinese)
Rubyonrails(Chinese)Rubyonrails(Chinese)
Rubyonrails(Chinese)heisda
 
J Ruby和Rails 让Ruby语言融入Java项目
J Ruby和Rails 让Ruby语言融入Java项目J Ruby和Rails 让Ruby语言融入Java项目
J Ruby和Rails 让Ruby语言融入Java项目George Ang
 
ASP.NET MVC 6 新功能探索
ASP.NET MVC 6 新功能探索ASP.NET MVC 6 新功能探索
ASP.NET MVC 6 新功能探索Will Huang
 
專案啟動與設定
專案啟動與設定專案啟動與設定
專案啟動與設定Shengyou Fan
 
Node js实践
Node js实践Node js实践
Node js实践myzykj
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用謝 宗穎
 
02.python.开发最佳实践
02.python.开发最佳实践02.python.开发最佳实践
02.python.开发最佳实践Na Lee
 
Cloudstack dev/user sharing
Cloudstack dev/user sharingCloudstack dev/user sharing
Cloudstack dev/user sharinggavin_lee
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介GO LL
 
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7Justin Lin
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuMarsZ Chen
 
Nodejs & NAE
Nodejs & NAENodejs & NAE
Nodejs & NAEq3boy
 
Package安裝與使用
Package安裝與使用Package安裝與使用
Package安裝與使用Shengyou Fan
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定Shengyou Fan
 
給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發Weizhong Yang
 
合久必分,分久必合
合久必分,分久必合合久必分,分久必合
合久必分,分久必合Qiangning Hong
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛Edward Kuo
 
Docker容器微服務 x WorkShop
Docker容器微服務 x WorkShopDocker容器微服務 x WorkShop
Docker容器微服務 x WorkShopPhilip Zheng
 

Similar to [OSDC12]相依性管理 - 以Ruby開發為例 (20)

Maven初级培训
Maven初级培训Maven初级培训
Maven初级培训
 
Rubyonrails(Chinese)
Rubyonrails(Chinese)Rubyonrails(Chinese)
Rubyonrails(Chinese)
 
J Ruby和Rails 让Ruby语言融入Java项目
J Ruby和Rails 让Ruby语言融入Java项目J Ruby和Rails 让Ruby语言融入Java项目
J Ruby和Rails 让Ruby语言融入Java项目
 
ASP.NET MVC 6 新功能探索
ASP.NET MVC 6 新功能探索ASP.NET MVC 6 新功能探索
ASP.NET MVC 6 新功能探索
 
專案啟動與設定
專案啟動與設定專案啟動與設定
專案啟動與設定
 
Node js实践
Node js实践Node js实践
Node js实践
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用
 
02.python.开发最佳实践
02.python.开发最佳实践02.python.开发最佳实践
02.python.开发最佳实践
 
Cloudstack dev/user sharing
Cloudstack dev/user sharingCloudstack dev/user sharing
Cloudstack dev/user sharing
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
 
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for Ubuntu
 
Docker基礎
Docker基礎Docker基礎
Docker基礎
 
Nodejs & NAE
Nodejs & NAENodejs & NAE
Nodejs & NAE
 
Package安裝與使用
Package安裝與使用Package安裝與使用
Package安裝與使用
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定
 
給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發
 
合久必分,分久必合
合久必分,分久必合合久必分,分久必合
合久必分,分久必合
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
 
Docker容器微服務 x WorkShop
Docker容器微服務 x WorkShopDocker容器微服務 x WorkShop
Docker容器微服務 x WorkShop
 

More from YC Ling

那些函數語言Tutorial沒有教我的事
那些函數語言Tutorial沒有教我的事那些函數語言Tutorial沒有教我的事
那些函數語言Tutorial沒有教我的事YC Ling
 
淺談Ruby process fork應用
淺談Ruby process fork應用淺談Ruby process fork應用
淺談Ruby process fork應用YC Ling
 
Learn Haskell The Easy Way
Learn Haskell The Easy WayLearn Haskell The Easy Way
Learn Haskell The Easy WayYC Ling
 
Lol Programming
Lol ProgrammingLol Programming
Lol ProgrammingYC Ling
 
Introduction of Reverse Engineering
Introduction of Reverse EngineeringIntroduction of Reverse Engineering
Introduction of Reverse EngineeringYC Ling
 
Lightning Talk: RichRC & Hirb-Unicode
Lightning Talk: RichRC & Hirb-UnicodeLightning Talk: RichRC & Hirb-Unicode
Lightning Talk: RichRC & Hirb-UnicodeYC Ling
 
Learning Ruby with RubyWarrior
Learning Ruby with RubyWarriorLearning Ruby with RubyWarrior
Learning Ruby with RubyWarriorYC Ling
 

More from YC Ling (7)

那些函數語言Tutorial沒有教我的事
那些函數語言Tutorial沒有教我的事那些函數語言Tutorial沒有教我的事
那些函數語言Tutorial沒有教我的事
 
淺談Ruby process fork應用
淺談Ruby process fork應用淺談Ruby process fork應用
淺談Ruby process fork應用
 
Learn Haskell The Easy Way
Learn Haskell The Easy WayLearn Haskell The Easy Way
Learn Haskell The Easy Way
 
Lol Programming
Lol ProgrammingLol Programming
Lol Programming
 
Introduction of Reverse Engineering
Introduction of Reverse EngineeringIntroduction of Reverse Engineering
Introduction of Reverse Engineering
 
Lightning Talk: RichRC & Hirb-Unicode
Lightning Talk: RichRC & Hirb-UnicodeLightning Talk: RichRC & Hirb-Unicode
Lightning Talk: RichRC & Hirb-Unicode
 
Learning Ruby with RubyWarrior
Learning Ruby with RubyWarriorLearning Ruby with RubyWarrior
Learning Ruby with RubyWarrior
 

[OSDC12]相依性管理 - 以Ruby開發為例

  • 2. About Me • 大貓 (YC Ling, @miaout17) • 2004年因為奇妙的機緣開始學習Ruby – RPG Maker XP – Rails? 能吃嗎?
  • 3. About Me • 大貓 (YC Ling, @miaout17) • 業餘Ruby遊戲開發者(2004~2007) • C++/Lua/ActionScript遊戲開發者(2007~2010) • Java/Ruby Web開發者(2010~now) • 業餘Functional Programming愛好者 • Github: https://github.com/miaout17
  • 4. 這場分享 • 不是來傳Ruby教的 • 沒什麼Ruby程式碼,不會Ruby也能聽懂 • 分享我對「高階語言相依性管理」的想法 – Ruby開發流程很方便 – 自Ruby開發流程抽取與語言無關的概念
  • 5. Top 10 Programmer Excuses Google: 2011 COSCUP Lightning Talk 嵌入式開發的故事
  • 8. 高階語言開發的相依性 Applications How can we make Libraries it more smooth? Virtual Machine/Interpreter/Compiler Abstraction! Native Code / Libraries Write once, debug run anywhere OS Hardware
  • 9. High-Level Languages Development in 2012 should… 1. 容易安裝、切換執行環境 2. 容易安裝函式庫 3. 確保所有開發者、部署環境使用相同版本 的函式庫 4. 使用版本控制系統,程式化地管理相依性 5. 函式庫應使用一致的版號規則描述相容性
  • 10. “Getting Started” Scenario Install environment Clone the project Install project dependencies Run the program Execute unit test TDD
  • 11. 安裝 Ruby Rubies Install environment $ apt-get install ruby $ yum –y install ruby Clone the project Install project • Not always up-to-date dependencies • Always not up-to-date • Multiple Rubies: MRI Execute unit test 1.8.7, 1.9.2, 1.9.3, REE, JRuby, Ru TDD binius, IronRuby, MacRuby, …
  • 12. RVM (Ruby Version Manager) 安裝RVM Install environment $ curl -L get.rvm.io | bash -s stable Clone the project 安裝Rubies $ rvm install 1.8.7 Install project $ rvm install 1.9.3-p125 dependencies $ rvm install jruby 切換不同Rubies Execute unit test $ rvm use 1.8.7 $ rvm use 1.9.3 --default TDD See Also: PerlBrew, PythonBrew, PHPBrew…
  • 14. 安裝環境 $ rvm install 1.9.3 Install environment Clone the project Install project dependencies Execute unit test TDD
  • 15. 下載專案源始碼 Install environment $ git clone git://github.com/rails/rails.git Clone the project Install project dependencies Execute unit test TDD
  • 16. Library Management in Ruby • 主流工具: Install environment – RubyGems: 管理Ruby套件 – Bundler: 管理Application與Gem的 Clone the project 相依性 Install project dependencies Execute unit test TDD
  • 17. RubyGems 安裝gem及其相依的gems $ gem install rails $ gem install rails –v=2.3.5 更新gems $ gem update 發佈gems $ gem push foo-1.0.0.gem Yes. A lot of languages can do this. See Also: pip, cpan, pear, onion, cabal, npm, maven, ivy…
  • 19. Gem 相依性 固定版本 Devise s.add_dependency ’devise', ‘1.5.0' 2.0.0 最小版本 Broken! Devise s.add_dependency ’devise', ‘>= 1.5.0' 1.6.0 版本範圍 Library Devise s.add_dependency ’devise', ‘>= 1.5’, ‘< 2.0’ Foobar 1.5.0 “Twiddle Wakka” s.add_dependency ’devise', ‘~> 1.5’ # ‘>= 1.5’, ‘< 2.0’ s.add_dependency ’devise', ‘~> 1.5.1’ # ‘>=1.5.1’, ‘< 1.6’ Just a shortcut?
  • 20. Semantic Versioning • Authored by Tom Preston-Werner, inventor of Gravatars and cofounder of GitHub • 一致的版號規則: Major.Minor.Patch • Rails 3.1.10 – Major version: 3 – Minor version: 1 – Patch version: 10
  • 21. Semantic Versioning • Major version change – 不向下相容 – Ex. Rails 2.3.7 -> 3.0.0 • Minor version change – 向下相容,增加新功能 – Ex. Rails 3.0.10 -> 3.1.0 • Patch version change – 向下相容,只修正bug – Ex. Rails 3.1.0 -> 3.1.1
  • 22. Semantic Versioning • 例外: Major version 0為早期開發 – 0.0.1, 0.0.2, 0.9.4 什麼都可能不相容 • 更多細節請見 http://semver.org/ – Pre-release – Tag name – Semantic versioning v2.0.0-rc1 • See also: Apache APR Version Numbering
  • 23. Semantic Versioning • Semantic Version + Twiddle Wakka – 使用一致的版號規則描述相容性 – 簡潔地指定「相容的版本區間」 s.add_dependency ’devise', ‘~> 1.5’ # ‘>= 1.5’, ‘< 2.0’ s.add_dependency ’devise', ‘~> 1.5.0’ # ‘>=1.5.0’, ‘< 1.6’ • Encouraged by the Ruby community – http://robots.thoughtbot.com/post/2508037841/twiddle-wakka – http://www.slideshare.net/copiousfreetime/gemology – 許多專案Follow此規則
  • 24. 為什麼需要Bundler? Installed Gems Rails Broken! 3.0.0 Execute with Rails Sqlite3 Execute with 2.3.7 1.3.3 Bundler Bundler Project Project Alala Devise Wahaha 2.0.0 JSON 1.2.1
  • 25. Gem v.s. Bundler • Gem – 安裝/反安裝/發佈gem – Gemspec管理gem與gem的相依性 • Bundler – 管理application與gem的相依性 • 幫你把application需要的gem一次全部裝好 • 確保所有開發者及部署使用相同版本的gem – 題外話:bundler也能拿來開發gem
  • 26. Bundler 在Gemfile中設定相依性 See Also: gradle, maven, ivy, sbt, virtualenv, carton
  • 27. Bundler bundle install 執行`bundle install`: 1. 計算並安裝所需要的gem 2. 產生 “Gemfile.lock”
  • 29. Bundler Ensure you are using right gems 在Shell中執行: $ bunlde exec ruby your_app.rb 或是在程式啟始點: require "rubygems" require "bundler/setup" 建議:所有的Ruby專案都可以使用Bundler
  • 30. Bundler with git 修改Gemfile $ vim Gemfile $ bundle install # or bundle update $ git add Gemfile Gemfile.lock; git commit 更新Gems $ bundle update $ git add Gemfile.lock; git commit
  • 31. 安裝相依之函式庫 Install environment Clone the project Install project $ bundle install dependencies Execute unit test TDD
  • 32. 執行單元測試… 使用正確版本的函式庫 Install environment Clone the project Install project dependencies $ bundle exec rake test Execute unit test TDD
  • 33. Wrapping up $ rvm install 1.9.3-p125 Install environment $ git clone git://github.com/rails/rails.git Clone the project $ cd rails Install project dependencies $ bundle install $ bundle exec rake test Execute unit test TDD
  • 35. High-Level Languages Development in 2012 should… 1. 容易安裝、切換執行環境 2. 容易安裝函式庫 3. 確保所有開發者、部署環境使用相同版本 的函式庫 4. 使用版本控制系統,程式化地管理相依性 5. 函式庫應使用一致的版號規則描述相容性
  • 37. PHPBrew, Onion https://github.com/c9s/phpbrew Brew & manage PHP versions in pure PHP at HOME https://github.com/c9s/Onion Onion, The fast approach to build/bundle PEAR packages for PHP.
  • 38. Carton Carton is a new command to manage Perl module dependencies for your applications. Like gem bundler for Ruby, Carton solves the issue of "upgrading CPAN modules broke my code" by allowing you to lock and freeze dependencies. Carton makes it easy to manage and reproduce module installations on any environments.
  • 39.
  • 40.