Class: Capistrano::Env::Config
- Inherits:
-
Object
- Object
- Capistrano::Env::Config
- Defined in:
- lib/capistrano/env/config.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Instance Method Summary collapse
- #add(name_or_regexp, val = nil, &block) ⇒ Object
- #capenv_content ⇒ Object
- #capenv_file ⇒ Object
- #envs ⇒ Object
- #formatter_class ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
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
#formatter ⇒ Object
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_content ⇒ Object
49 50 51 |
# File 'lib/capistrano/env/config.rb', line 49 def capenv_content formatter_class.format(envs) end |
#capenv_file ⇒ Object
45 46 47 |
# File 'lib/capistrano/env/config.rb', line 45 def capenv_file formatter_class.filename end |
#envs ⇒ Object
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_class ⇒ Object
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 |