From bf69d6ee6d64d7099d88fae2914732ad94ebd4ef Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 13 Oct 2011 10:01:18 -0400 Subject: [PATCH] update things and docs and stuff --- README.md | 27 +++++++++++++++++++++++++++ bin/penchant | 5 +++-- lib/penchant/dot_penchant.rb | 5 ++--- lib/penchant/gemfile.rb | 8 ++++---- lib/penchant/version.rb | 2 +- script/gemfile | 4 ++-- script/hooks/pre-commit | 2 +- template/script/hooks/pre-commit | 2 +- 8 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 994b9e5..999f94f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ Yeah, it's a `Gemfile` with ERB in it: <% env :remote do %> gem 'guard', :git => 'git://github.com/johnbintz/guard.git' <% end %> + +<% no_deployment do %> + gem 'os-specific-things' +<% end %> ``` Use `script/gemfile local` to get at the local ones, and `script/gemfile remote` to get at the remote ones. @@ -38,6 +42,29 @@ It then runs `bundle install`. You can also run `penchant gemfile ENV`. +### Deployment mode + +Use `no_deployment` blocks to indicate gems that shouldn't even appear in `Gemfiles` destined for +remote servers. *Very* helpful when you have OS-specific gems and are developing on one platform +and deploying on another: + +``` erb +<% no_deployment do %> + require 'rbconfig' + case RbConfig::CONFIG['host_os'] + when /darwin/ + gem 'growl_notify' + gem 'growl' + gem 'rb-fsevent' + when /linux/ + gem 'libnotify', :require => nil + end +<% end %> +``` + +Run `penchant gemfile ENV --deployment` to get this behavior. This is run by default when the +pre-commit git hook runs. + ## initialize-environment Get new developers up to speed fast! `script/initialize-environment` does the following when run: diff --git a/bin/penchant b/bin/penchant index a75aa7e..ae6b13b 100755 --- a/bin/penchant +++ b/bin/penchant @@ -24,11 +24,12 @@ class PenchantCLI < Thor gemfile(:remote) end + method_options :deployment => false desc "gemfile ENV", "Switch the gemfile environment, or rebuild the current environment if not given" def gemfile(env = get_current_env) if env - puts "[penchant] Rebunding for #{env} environment..." - Penchant::Gemfile.do_full_env_switch!(env) + puts "[penchant] Rebunding for #{env} environment#{options[:deployment] ? ", deployment mode" : ''}..." + Penchant::Gemfile.do_full_env_switch!(env, options[:deployment]) end gemfile = Penchant::Gemfile.new diff --git a/lib/penchant/dot_penchant.rb b/lib/penchant/dot_penchant.rb index 7174201..02c51b3 100644 --- a/lib/penchant/dot_penchant.rb +++ b/lib/penchant/dot_penchant.rb @@ -1,14 +1,14 @@ module Penchant class DotPenchant class << self - def run(env = nil) + def run(env = nil, deployment = false) dot_penchant = new dot_penchant.run(env) dot_penchant end end - def run(env = nil) + def run(env = nil, deployment = false) instance_eval(File.read('.penchant')) end @@ -22,7 +22,6 @@ module Penchant def gemfile? File.file?('Gemfile') end - end end diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 61b5fe6..7a347fd 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -7,13 +7,13 @@ module Penchant class << self def do_full_env_switch!(env, deployment = false) gemfile = Penchant::Gemfile.new - gemfile.run_dot_penchant!(env) + gemfile.run_dot_penchant!(env, deployment) if !gemfile.has_gemfile_erb? return false end - gemfile.switch_to!(env) + gemfile.switch_to!(env, deployment) end end @@ -56,8 +56,8 @@ module Penchant end end - def run_dot_penchant!(env) - DotPenchant.run(env || environment) if has_dot_penchant? + def run_dot_penchant!(env, deployment) + DotPenchant.run(env || environment, deployment) if has_dot_penchant? end private diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index bbf4fb0..8733841 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.0.4" + VERSION = "0.0.5" end diff --git a/script/gemfile b/script/gemfile index 1edd3b3..a4aec05 100755 --- a/script/gemfile +++ b/script/gemfile @@ -3,9 +3,9 @@ require 'rubygems' require 'penchant' -if Penchant::Gemfile.do_full_env_switch!(ARGV[0], true) +if Penchant::Gemfile.do_full_env_switch!(ARGV[0]) system %{bundle} - puts "Gemfile switched to #{ARGV[0]} in deployment mode" + puts "Gemfile switched to #{ARGV[0]}" else exit 0 end diff --git a/script/hooks/pre-commit b/script/hooks/pre-commit index e1b1e1c..42c60b3 100755 --- a/script/hooks/pre-commit +++ b/script/hooks/pre-commit @@ -4,7 +4,7 @@ OLD_GIT_DIR=$GIT_DIR if [ "$(penchant gemfile-env)" != "remote" ]; then unset GIT_DIR - penchant gemfile remote + penchant gemfile remote --deployment GIT_DIR=$OLD_GIT_DIR git add Gemfile* fi diff --git a/template/script/hooks/pre-commit b/template/script/hooks/pre-commit index e1b1e1c..42c60b3 100755 --- a/template/script/hooks/pre-commit +++ b/template/script/hooks/pre-commit @@ -4,7 +4,7 @@ OLD_GIT_DIR=$GIT_DIR if [ "$(penchant gemfile-env)" != "remote" ]; then unset GIT_DIR - penchant gemfile remote + penchant gemfile remote --deployment GIT_DIR=$OLD_GIT_DIR git add Gemfile* fi