Module: CapistranoConfiguration

Defined in:
lib/capistrano-configuration.rb

Defined Under Namespace

Classes: CapistranoConfigurationError

Constant Summary collapse

@@current_config =
nil
@@configurations =
Hash.new
@@locations =
Hash.new
@@current_envs =
Array.new
@@original_envs =
Array.new

Instance Method Summary collapse

Instance Method Details

#config(setting, value) ⇒ Object



37
38
39
40
# File 'lib/capistrano-configuration.rb', line 37

def config(setting, value)
  raise CapistranoConfigurationError.new("You cannot call config without wrapping it inside a configure or environment call.") if @@current_config.nil?
  current_level[setting] = value
end

#configure(config, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/capistrano-configuration.rb', line 16

def configure(config, options={})
  raise CapistranoConfigurationError.new("You cannot call configure without first closing an already existing configure.") unless @@current_config.nil?
  raise CapistranoConfigurationError.new("Configure is designed to work with a block. Please pass it one.") unless block_given?
  @@current_config = config.to_sym
  @@configurations[@@current_config] ||= Hash.new
  @@locations[@@current_config] = options[:to_file] if options[:to_file]
  yield
  @@current_config = nil
end

#environment(env) ⇒ Object Also known as: context



26
27
28
29
30
31
32
33
34
# File 'lib/capistrano-configuration.rb', line 26

def environment(env)
  raise CapistranoConfigurationError.new("You cannot call environment without wrapping it inside a configure call.") if @@current_config.nil?
  raise CapistranoConfigurationError.new("Environment is designed to work with a block. Please pass it one.") unless block_given?
  current_level[env] ||= Hash.new
  @@original_envs << @@current_envs.dup
  @@current_envs << env
  yield
  @@current_envs = @@original_envs.pop
end

#file_path_for(configuration, default = '.') ⇒ Object



42
43
44
45
46
47
48
# File 'lib/capistrano-configuration.rb', line 42

def file_path_for(configuration, default='.')
  if @@locations[configuration.to_sym]
    @@locations[configuration.to_sym]
  else
    "#{default}/#{configuration}.yml"
  end
end