Sha256: 36fcdc340ba4ef64cea91a2486daa5a3c4ba12897cc38f357104925b318c6dc1
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
module Capistrano module Env class Config attr_accessor :formatter def initialize @formatter = :ruby @values = {} @keys = [] end def add(name_or_regexp, val = nil, &block) if val && name_or_regexp.is_a?(String) @values[name_or_regexp] = val else @keys << [name_or_regexp, block] end end def formatter_class @formatter_class ||= begin require "capistrano/env/formatter/#{@formatter}_formatter" Capistrano::Env::Formatter.const_get "#{formatter.capitalize}Formatter" end end def envs result = {} @keys.each do |key, block| key_values = key.is_a?(Regexp) ? ENV.select { |x| x =~ key } : ENV.select { |x| x == key } key_values = Hash[key_values.map { |k, v| [block.call(k), v] }] if block result.merge!(key_values) end result.merge(@values) end def capenv_file "capenv.#{formatter_class.file_ext}" end def capenv_content formatter_class.format(envs) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
capistrano-env-0.1.2 | lib/capistrano/env/config.rb |
capistrano-env-0.1.1 | lib/capistrano/env/config.rb |