add property support, too

This commit is contained in:
John Bintz 2012-07-05 18:27:59 -04:00
parent dbc98424d8
commit 9713be8dfd
2 changed files with 36 additions and 5 deletions

View File

@ -249,3 +249,17 @@ Feature: Gemfiles
# generated by penchant, environment: local
gem "one", "1.2.3", {:path=>"../cats"}
"""
Scenario: Define special expansions for properties
Given I have the file "Gemfile.penchant" with the content:
"""
defaults_for env(:local), :path => '../%s'
property(:github) { |name| { :git => "git://github.com/#{name}/%s.git" } }
gem 'one', :github => 'john'
"""
When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following content:
"""
# generated by penchant, environment: local
gem "one", {:git=>"git://github.com/john/one.git"}
"""

View File

@ -121,6 +121,7 @@ module Penchant
@available_environments = []
@defined_git_repos = []
@defaults = {}
@properties = {}
@_current_env_defaults = {}
end
@ -150,6 +151,10 @@ module Penchant
end
end
def property(name, &block)
@properties[name] = block
end
def for_environment?(envs)
envs.include?(environment) || environment == ANY_ENVIRONMENT
end
@ -192,13 +197,25 @@ module Penchant
end
def process_options(gem_name, template = {})
Hash[
_defaults_for(gem_name).dup.merge(template).collect { |key, value|
properties = {}
property_stack = _defaults_for(gem_name).dup.merge(template).to_a
while !property_stack.empty?
key, value = property_stack.shift
if @properties[key]
@properties[key].call(*([ value ].flatten)).each do |k, v|
property_stack.push([ k, v ])
end
else
value = value % gem_name if value.respond_to?(:%)
[ key, value ]
}.sort
]
properties[key] = value
end
end
Hash[properties.sort]
end
def _defaults_for(gem_name)