factor out some defaults handling

This commit is contained in:
John Bintz 2012-10-09 11:24:12 -04:00
parent 7af1e933b2
commit 152067f925
4 changed files with 26 additions and 13 deletions

View File

@ -6,4 +6,5 @@ module Penchant
autoload :Env, 'penchant/env'
autoload :FileProcessor, 'penchant/file_processor'
autoload :PenchantFile, 'penchant/penchant_file'
autoload :Defaults, 'penchant/defaults'
end

11
lib/penchant/defaults.rb Normal file
View File

@ -0,0 +1,11 @@
module Penchant
class Defaults
def initialize
@defaults = {}
end
def [](key)
@defaults[key.to_s] ||= {}
end
end
end

View File

@ -20,7 +20,7 @@ module Penchant
@data = data
@available_environments = []
@defined_git_repos = []
@defaults = {}
@defaults = Defaults.new
@properties = {}
@_current_env_defaults = {}
@ -37,6 +37,10 @@ module Penchant
@output.join("\n")
end
def <<(string)
@output << string
end
def env(*args)
options = {}
options = args.pop if args.last.kind_of?(::Hash)
@ -71,11 +75,8 @@ module Penchant
end
def opposites(left, right)
@defaults[Env.new(left).to_s] ||= {}
@defaults[Env.new(left).to_s][:opposite] = right
@defaults[Env.new(right).to_s] ||= {}
@defaults[Env.new(right).to_s][:opposite] = left
@defaults[Env.new(left)][:opposite] = right
@defaults[Env.new(right)][:opposite] = left
end
def for_environment?(envs)
@ -104,7 +105,7 @@ module Penchant
end
def ruby(version)
@output << %{ruby "#{version}"}
self << %{ruby "#{version}"}
end
protected
@ -180,7 +181,7 @@ module Penchant
def _defaults_for(gem_name)
result = @_current_env_defaults
result.merge(@defaults[gem_name.to_s] || {})
result.merge(@defaults[gem_name] || {})
end
def current_os

View File

@ -25,7 +25,7 @@ module Penchant
args << options if !options.empty?
@output << %{gem #{args_to_string(args)}}
self << %{gem #{args_to_string(args)}}
end
def gemspec
@ -46,16 +46,16 @@ module Penchant
end
def group(*args, &block)
@output << ""
@output << %{group #{args_to_string(args)} do}
self << ""
self << %{group #{args_to_string(args)} do}
call_and_indent_output(block)
@output << %{end}
self << %{end}
end
def source(*args)
@output << %{source #{args_to_string(args)}}
self << %{source #{args_to_string(args)}}
end
end
end