tricking bundler
DESCRIPTION
Scripts to manage symlinks from your code directory to Bundler's gems directoryTRANSCRIPT
Rome Ruby Social Club - March 23, 2012
Tricking Bundleraka developing app & gem w/o roundtripsaka no moregem.git (at master) is not checked out. Please run `bundle install`
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Bundler + Git
Gem dependencies manager (that gets caching right ;-)
Allows to install gems from Git repositories
This trick is for Git gems only
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
How does it work
Parses Gemfile & Gemfile.lock
git fetch && git checkout in`gem environment gemdir`/bundler/gems/$NAME-$REF12
Add the checked out directory to Ruby’s $LOAD_PATH
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Problem
Your project is in ~/code/app
Your gem is in ~/code/gem
You run the app and need to change the gem code
cd ~/code/gem; <code>; git commit; git push; cd ~/code/app; bundle up gem # DOESN’T fit the job
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Symlinks to the rescue!
Bundler directory contains all git-fetched gems with this format:
$GEM_NAME-$REF12 (first 12 chars of the HEAD SHA1 commit id)
Bash script gets ~/code/gems HEAD ref && ln -s ~/code/gem to the directory bundler expects the gem in
Profit!
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Solution
You edit the gem code directly in your ~/code/gem - app picks it up
Once done, git commit && git show to get HEAD SHA1 id
Update SHA1 in Gemfile.lock directly
symlink-gem ../gem
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Switching branches?
master branch needs commit c4feb4be
develop branch needs commit de4db3ef
(develop) git co master; for gem in a b c d; do symlink-gem ../$gem; done# DOESN’T cut the job either ;-)
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Bundle::LockFileParser is your friend
Ruby script gets all dependencies in a nicely wrapped Array of Sources
For each Git-fetched $gem, check out the commit required by Gemfile.lock in your ~/code/$gem
%x{ symlink-gem #{gem} }
Why not git post-checkout-hook? :)
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Switch branchesw/post-checkout-hook
18:04:02 [vjt@debian ~/code/app] (develop) $ git co master Switched to branch 'master'
[git://github.com/vjt/rtf.git] Already on 'master'
[git://github.com/vjt/dep1.git] HEAD is now at df61eac... Fixed stuff
[git://github.com/vjt/dep2.git] Previous HEAD position was 45509fa... Experimental stuffSwitched to branch 'master'
[git://github.com/ifad/activerecord-sybase-adapter.git] Already on 'master'
Saturday, March 24, 2012
Rome Ruby Social Club - March 23, 2012
Thanks!
@vjt
http://sindro.me/
http://github.com/vjt
Saturday, March 24, 2012