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} 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 env :local do
# expands to: # expands to:
# #
# gem 'flowerbox', :path => '../flowerbox' # gem 'flowerbox', :path => '../flowerbox', :require => nil
# gem 'guard-flowerbox', :path => '../guard-flowerbox' # gem 'guard-flowerbox', :path => '../guard-flowerbox', :require => nil
gems dev_gems, :path => '../%s' gems dev_gems, :path => '../%s'
end end
env :remote do env :remote do
# expands to: # expands to:
# #
# gem 'flowerbox', :git => 'git://github.com/johnbintz/flowerbox.git' # gem 'flowerbox', :git => 'git://github.com/johnbintz/flowerbox.git', :require => nil
# gem 'guard-flowerbox', :git => 'git://github.com/johnbintz/guard-flowerbox.git' # gem 'guard-flowerbox', :git => 'git://github.com/johnbintz/guard-flowerbox.git', :require => nil
gems dev_gems, :git => 'git://github.com/johnbintz/%s.git' gems dev_gems, :git => 'git://github.com/johnbintz/%s.git'
end end

View File

@ -182,3 +182,29 @@ Feature: Gemfiles
Then I should get the following repositories: Then I should get the following repositories:
| git://github.cats/two.git | | 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 @data = data
@available_environments = [] @available_environments = []
@defined_git_repos = [] @defined_git_repos = []
@defaults = {}
end end
def result(_env, _is_deployment) def result(_env, _is_deployment)
@ -129,6 +130,12 @@ module Penchant
yield if args.include?(current_os) yield if args.include?(current_os)
end end
def defaults_for(*args)
defaults = args.pop
args.flatten.each { |gem| @defaults[gem.to_s] = defaults.dup }
end
protected protected
def args_to_string(args) def args_to_string(args)
args.inspect[1..-2] args.inspect[1..-2]
@ -154,7 +161,7 @@ module Penchant
def process_options(gem_name, template = {}) def process_options(gem_name, template = {})
Hash[ Hash[
template.collect { |key, value| template.merge(_defaults_for(gem_name)).collect { |key, value|
value = value % gem_name if value.respond_to?(:%) value = value % gem_name if value.respond_to?(:%)
[ key, value ] [ key, value ]
@ -162,6 +169,10 @@ module Penchant
] ]
end end
def _defaults_for(gem_name)
@defaults[gem_name.to_s] || {}
end
def current_os def current_os
require 'rbconfig' require 'rbconfig'
case host_os = RbConfig::CONFIG['host_os'] case host_os = RbConfig::CONFIG['host_os']
@ -242,7 +253,7 @@ module Penchant
version = args.first version = args.first
options = process_options(gem_name, template) options = process_options(gem_name.first, template)
args = [ gem_name.first ] args = [ gem_name.first ]
args << version if version args << version if version

View File

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