defaults_for

This commit is contained in:
John Bintz 2012-06-20 09:34:47 -04:00
parent bc09df6bce
commit 08803b76ce
4 changed files with 47 additions and 7 deletions

View File

@ -40,19 +40,22 @@ no_deployment do
dev_gems = %w{flowerbox guard-flowerbox}
# set up defaults for certain gems that are probably being used in envs
defaults_for dev_gems, :require => nil
env :local do
# expands to:
#
# gem 'flowerbox', :path => '../flowerbox'
# gem 'guard-flowerbox', :path => '../guard-flowerbox'
# gem 'flowerbox', :path => '../flowerbox', :require => nil
# gem 'guard-flowerbox', :path => '../guard-flowerbox', :require => nil
gems dev_gems, :path => '../%s'
end
env :remote do
# expands to:
#
# gem 'flowerbox', :git => 'git://github.com/johnbintz/flowerbox.git'
# gem 'guard-flowerbox', :git => 'git://github.com/johnbintz/guard-flowerbox.git'
# gem 'flowerbox', :git => 'git://github.com/johnbintz/flowerbox.git', :require => nil
# gem 'guard-flowerbox', :git => 'git://github.com/johnbintz/guard-flowerbox.git', :require => nil
gems dev_gems, :git => 'git://github.com/johnbintz/%s.git'
end

View File

@ -182,3 +182,29 @@ Feature: Gemfiles
Then I should get the following repositories:
| git://github.cats/two.git |
Scenario: Propose defaults for a gem
Given I have the file "Gemfile.penchant" with the content:
"""
defaults_for 'one', :path => '../%s'
gem 'one', '1.2.3'
"""
When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following content:
"""
# generated by penchant, environment: local
gem "one", "1.2.3", {:path=>"../one"}
"""
@wip
Scenario: Propose defaults for an array of gems
Given I have the file "Gemfile.penchant" with the content:
"""
defaults_for ['one'], :path => '../%s'
gem 'one', '1.2.3'
"""
When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following content:
"""
# generated by penchant, environment: local
gem "one", "1.2.3", {:path=>"../one"}
"""

View File

@ -102,6 +102,7 @@ module Penchant
@data = data
@available_environments = []
@defined_git_repos = []
@defaults = {}
end
def result(_env, _is_deployment)
@ -129,6 +130,12 @@ module Penchant
yield if args.include?(current_os)
end
def defaults_for(*args)
defaults = args.pop
args.flatten.each { |gem| @defaults[gem.to_s] = defaults.dup }
end
protected
def args_to_string(args)
args.inspect[1..-2]
@ -154,7 +161,7 @@ module Penchant
def process_options(gem_name, template = {})
Hash[
template.collect { |key, value|
template.merge(_defaults_for(gem_name)).collect { |key, value|
value = value % gem_name if value.respond_to?(:%)
[ key, value ]
@ -162,6 +169,10 @@ module Penchant
]
end
def _defaults_for(gem_name)
@defaults[gem_name.to_s] || {}
end
def current_os
require 'rbconfig'
case host_os = RbConfig::CONFIG['host_os']
@ -242,7 +253,7 @@ module Penchant
version = args.first
options = process_options(gem_name, template)
options = process_options(gem_name.first, template)
args = [ gem_name.first ]
args << version if version

View File

@ -1,3 +1,3 @@
module Penchant
VERSION = "0.2.5"
VERSION = "0.2.6"
end