diff --git a/README.md b/README.md index a94b495..ca885a0 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,15 @@ no_deployment do gems dev_gems, :github => 'johnbintz' end + # an even shorter way to specify environments! + # in remote env, expands to: + # gem 'bullseye', :git => 'git://github.com/johnbintz/bullseye.git' + # in local env, expands to: + # gem 'bullseye', :path => '../bullseye' + env :remote, :opposite => :local do + gem 'bullseye', :github => 'johnbintz' + end + # only expanded on Mac OS X os :darwin do gem 'rb-fsevent' diff --git a/features/ruby_gemfile.feature b/features/ruby_gemfile.feature index b67b407..2a11fa3 100644 --- a/features/ruby_gemfile.feature +++ b/features/ruby_gemfile.feature @@ -235,6 +235,34 @@ Feature: Gemfiles gem "one", "1.2.3", {:path=>"../one"} """ + Scenario: Create opposite environment gem assumptions to cut down on repetition + 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" } } + + env :remote, :opposite => :local do + gem 'one', :github => 'johnbintz', :require => nil + end + env :local, :opposite => :remote do + gem 'two', :path => '../%s', :require => nil + 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", {:path=>"../one", :require=>nil} + gem "two", {:path=>"../two", :require=>nil} + """ + When I rebuild the Gemfile for "remote" mode + Then the file "Gemfile" should have the following content: + """ + # generated by penchant, environment: remote + gem "one", {:git=>"git://github.com/johnbintz/one.git", :require=>nil} + gem "two", {:require=>nil} + """ + Scenario: Override defaults for an environment Given I have the file "Gemfile.penchant" with the content: """ diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 92fb806..8ff92e7 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -138,6 +138,9 @@ module Penchant end def env(*args) + options = {} + options = args.pop if args.last.kind_of?(::Hash) + @available_environments += args if block_given? @@ -145,6 +148,16 @@ module Penchant @_current_env_defaults = _defaults_for(Env.new(environment)) yield @_current_env_defaults = {} + else + if options[:opposite] + if for_environment?([ options[:opposite] ].flatten) + @_current_env_defaults = _defaults_for(Env.new(environment)) + @_strip_pathing_options = true + yield + @_strip_pathing_options = false + @_current_env_defaults = {} + end + end end else Penchant::Gemfile::Env.new(args.shift) @@ -203,7 +216,22 @@ module Penchant def process_options(gem_name, template = {}) properties = {} - property_stack = _defaults_for(gem_name).dup.merge(template).to_a + property_stack = template.to_a + + original_properties = process_option_stack(gem_name, property_stack) + + if @_strip_pathing_options + [ :git, :branch, :path ].each { |key| original_properties.delete(key) } + end + + properties = process_option_stack(gem_name, _defaults_for(gem_name).to_a).merge(original_properties) + + Hash[properties.sort] + end + + def process_option_stack(gem_name, stack) + property_stack = stack.dup + properties = {} while !property_stack.empty? key, value = property_stack.shift @@ -227,8 +255,8 @@ module Penchant properties[key] = value end end - - Hash[properties.sort] + + properties end def _defaults_for(gem_name) @@ -322,12 +350,13 @@ module Penchant args = [ gem_name.first ] args << version if version - args << options if !options.empty? if options[:git] @defined_git_repos << Penchant::Repo.new(options[:git]) end + args << options if !options.empty? + @output << %{gem #{args_to_string(args)}} end diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index d36e449..945bfb6 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.2.20" + VERSION = "0.2.21" end