defaults for things in environments

This commit is contained in:
John Bintz 2012-06-20 13:25:43 -04:00
parent 08803b76ce
commit 98239ee141
2 changed files with 44 additions and 3 deletions

View File

@ -195,7 +195,6 @@ Feature: Gemfiles
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:
"""
@ -208,3 +207,18 @@ Feature: Gemfiles
# generated by penchant, environment: local
gem "one", "1.2.3", {:path=>"../one"}
"""
Scenario: Propose defaults for an environment
Given I have the file "Gemfile.penchant" with the content:
"""
defaults_for env(:local), :path => '../%s'
env :local do
gem 'one', '1.2.3'
end
"""
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

@ -83,6 +83,22 @@ module Penchant
gemfile_header['deployment mode'] != nil
end
class Env
attr_accessor :name
def initialize(name)
@name = name.to_s
end
def ==(other)
@name == other.name
end
def to_s
"@#{name}"
end
end
class FileProcessor
attr_reader :environment, :is_deployment, :available_environments, :defined_git_repos
@ -103,6 +119,8 @@ module Penchant
@available_environments = []
@defined_git_repos = []
@defaults = {}
@_current_env_defaults = {}
end
def result(_env, _is_deployment)
@ -119,7 +137,15 @@ module Penchant
def env(*args)
@available_environments += args
yield if args.include?(environment)
if block_given?
if args.include?(environment)
@_current_env_defaults = _defaults_for(Env.new(environment))
yield
@_current_env_defaults = {}
end
else
Penchant::Gemfile::Env.new(args.shift)
end
end
def no_deployment
@ -170,7 +196,8 @@ module Penchant
end
def _defaults_for(gem_name)
@defaults[gem_name.to_s] || {}
result = @_current_env_defaults
result.merge(@defaults[gem_name.to_s] || {})
end
def current_os