Class: Capistrano::Env::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/env/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
# File 'lib/capistrano/env/config.rb', line 8

def initialize
  @values = {}
  @keys = []
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



6
7
8
# File 'lib/capistrano/env/config.rb', line 6

def formatter
  @formatter
end

Instance Method Details

#add(name_or_regexp, val = nil, &block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/capistrano/env/config.rb', line 20

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

#capenv_contentObject



49
50
51
# File 'lib/capistrano/env/config.rb', line 49

def capenv_content
  formatter_class.format(envs)
end

#capenv_fileObject



45
46
47
# File 'lib/capistrano/env/config.rb', line 45

def capenv_file
  formatter_class.filename
end

#envsObject



35
36
37
38
39
40
41
42
43
# File 'lib/capistrano/env/config.rb', line 35

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

#formatter_classObject



28
29
30
31
32
33
# File 'lib/capistrano/env/config.rb', line 28

def formatter_class
  @formatter_class ||= begin
                         require "capistrano/env/formatter/#{formatter}_formatter"
                         Capistrano::Env::Formatter.const_get "#{formatter.capitalize}Formatter"
                       end
end