Bundlerã®å ¬å¼ã®ããããã¼ã¸ãèªãã§ã¿ã
What is Bundler?
It tracks an application's code and the rubygems it needs to run,ããã¯ãã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãã¨ãrubygemsãåãã®ã«å¿ è¦ãªãã®ãç£è¦ããã
- track : ãã©ããç£è¦ã»è¿½è·¡ãã
so that an application will always have the exact gems (and versions) that it needs to run.ã¢ããªã±ã¼ã·ã§ã³ããåãã®ã«å¿ è¦ãªç確ãªgem(ã¨ãã®ãã¼ã¸ã§ã³)ã常åã§ããããã«ããã
- so that : ãã§ããããã«
- always have : 常å
- exact : ç確ãª
Getting Started
Getting started with bundler is easy! Open a terminal window and run this command:bundler ãå§ããã®ã¯ç°¡åã ã! ã¿ã¼ããã«ãéãã¦ã以ä¸ã®ã³ãã³ããå ¥åãã¦ã
$ gem install bundler
Specify your dependencies in a Gemfile in your project's root:ä¾åé¢ä¿ããGemfileã«æ¸ãã¦ãããªãã®ããã¸ã§ã¯ãã®ã«ã¼ããã£ã¬ã¯ããªã«æ ¼ç´ãã¦ã
- Specify : ããå«ãã
- dependencies : ä¾åé¢ä¿
source 'https://rubygems.org' gem 'nokogiri' gem 'rack', '~>1.1' gem 'rspec', :require => 'spec'
Install all of the required gems from your specified sources:以ä¸ã®ã³ãã³ãã§ãããªããæ¸ãããæãã gemãå ¨ã¦ã¤ã³ã¹ãã¼ã«ããã
- required : æãã
$ bundle install $ git add Gemfile Gemfile.lock
The second command adds the Gemfile and Gemfile.lock to your repository.2ã¤ãã®ã³ãã³ãã¯ãGemfileã¨ãGemfile.lockããªãã¸ããªã«å ¥ãã¦ãã
This ensures that other developers on your app, as well as your deployment environment, will all use the same third-party code that you are using now.ããã¯ãããªãã®ã¢ããªãããããä»ã®éçºè ããããªãã®éçºç°å¢ã®ã¿ãªãããããªãã使ã£ã¦ãããå ¨ã¦ã®ãµã¼ããã¼ãã£ã³ã¼ãã使ããããã«ãã¦ããããã¨ã確å®ã«ãã¦ãããã
- ensures : 確å®ã«ãããå®ããä¿éºãæãã
- as well as : ãã®åå¾ãAã ãã§ãªãBã
Inside your app, load up the bundled environmentãã³ãã«ããç°å¢ãããªãã®ã¢ããªã«å ¥ããã
require 'rubygems' require 'bundler/setup' # require your gems as usual require 'nokogiri'
訳注 : railsã ã¨ãã®é¨åã¯ããã«ã¯ããã£ã¦ããã
Run an executable that comes with a gem in your bundle:ããªãã® bundle ã«ãã gem ã®å®è¡ãã¡ã¤ã«ãèµ·åããã
$ bundle exec rspec spec/models
- executable : å®è¡ãã¡ã¤ã«
In some cases, running executables without bundle exec may work,å¾ã ã«ãã¦ãbundle exec ãªãã§ããã³ãã³ããå®è¡ã§ããã
- In some cases : å¾ã ã«ãã¦
if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.ããªãã®ã·ã¹ãã ã«å ¥ã£ã¦ãã gem ã¨ãbundle ã«å ¥ã£ã¦ãã gem ãã³ã³ããªã¯ããã¦ããªãã®ãçç±ã ã
However, this is unreliable and is the source of considerable pain.ãã©ãããã¯ä¿¡é ¼ãªããªãã¦ãå¤ãã®é¢åã®ç¨®ã¨ãªãã
- source of : åå
- considerable : ããªãã®
- pain : çã¿ãè¦å´ãæ·±ã
- However : ããã©ããããããªãã
- unreliable : ä¿¡é ¼ãªããªããé ¼ãã«ãªããªã
Even if it looks like it works, it may not work in the future or on another machine.ãã¨ãä»ããæãã«åãã¦ããããã«è¦ãã¦ããå°æ¥ãå¥ã®ãã·ã³ã§åãã¨ã¯éããªãã
- Even : ãã¨ããã§ã
Finally, if you want a way to get a shortcut to gems in your bundle:æå¾ã«ãgemã³ãã³ãã®ã·ã§ã¼ãã«ããã欲ããæ
$ bundle install --binstubs $ bin/rspec spec/models
The executables installed into bin are scoped to the bundle, and will always work.binãã£ã¬ã¯ããªã«ãbundleã®gemã³ãã³ããã¤ã³ã¹ãã¼ã«ããããã
ããã¯ãã¤ã§ãåä½ããã
ãããªæã