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.



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

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

Instance Attribute Details

#filemodeObject

Returns the value of attribute filemode.



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

def filemode
  @filemode
end

#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



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

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



56
57
58
# File 'lib/capistrano/env/config.rb', line 56

def capenv_content
  formatter_class.format(envs)
end

#capenv_fileObject



52
53
54
# File 'lib/capistrano/env/config.rb', line 52

def capenv_file
  formatter_class.filename
end

#capenv_filemodeObject



60
61
62
# File 'lib/capistrano/env/config.rb', line 60

def capenv_filemode
  filemode
end

#envsObject



42
43
44
45
46
47
48
49
50
# File 'lib/capistrano/env/config.rb', line 42

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



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

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