class AvoDeploy::Config

Attributes

config[R]
loaded_stage[R]
stages[R]
targets[R]

Public Class Methods

new() click to toggle source

Intializes the config object

# File lib/avodeploy/config.rb, line 28
def initialize
  @config = setup_config_defaults
  @stages = {}
  @targets = {}
  @loaded_stage = nil
end

Public Instance Methods

get(key) click to toggle source

Returns a configuration item if set

@param key [Symbol] configuration key @return [mixed] configuration value

# File lib/avodeploy/config.rb, line 70
def get(key)
  raise ArgumentError, "key #{key} is not set" unless @config.has_key?(key)

  @config[key]
end
inherit_strategy(strategy) click to toggle source

Loads a strategy. Because the strategy files are loaded in the specified order, it’s possible to override tasks. This is how inheritance of strategies is realized.

@param strategy [Symbol] the strategy to load

# File lib/avodeploy/config.rb, line 54
def inherit_strategy(strategy)
  AvoDeploy::Deployment.instance.log.debug "Loading deployment strategy #{strategy.to_s}..."

  strategy_file_path = File.dirname(__FILE__) + "/strategy/#{strategy.to_s}.rb"

  if File.exist?(strategy_file_path)
    require strategy_file_path
  else
    raise RuntimeError, "The requested strategy '#{strategy.to_s}' does not exist"
  end
end
merge(other_config) click to toggle source

Merges the configuration with another config hash

@param other_config [Hash] configuration hash @return [Hash] the merged hash

# File lib/avodeploy/config.rb, line 117
def merge(other_config)
  @config.merge(other_config)
end
set(key, value) click to toggle source

Sets a configuration item

@param key [Symbol] configuration key @param value [mixed] configuration value

# File lib/avodeploy/config.rb, line 39
def set(key, value)
  # compatibility with releases < 0.5
  if key == :strategy
    inherit_strategy(value)
    return
  end

  @config[key] = value
end
setup_stage(name, options = {}, &block) click to toggle source

Defines a stage

@param name [Symbol] stage name @param options [Hash] stage options @param block [Block] the stage configuration

# File lib/avodeploy/config.rb, line 91
def setup_stage(name, options = {}, &block)
  stages[name] = ''

  if options.has_key?(:desc)
    stages[name] = options[:desc]
  end

  if name.to_s == get(:stage).to_s
    @loaded_stage = name

    instance_eval(&block)
  end
end
target(name, options = {}) click to toggle source

Defines a deployment target

@param name [Symbol] the deployment targets’ name @param options [Hash] target options

# File lib/avodeploy/config.rb, line 109
def target(name, options = {})
  @targets[name] = AvoDeploy::Target.new(name, options)
end
task(name, options = {}, &block) click to toggle source

Defines a task

@param name [Symbol] task name @param options [Hash] task options @param block [Block] the code to be executed when the task is started

# File lib/avodeploy/config.rb, line 81
def task(name, options = {}, &block)
  AvoDeploy::Deployment.instance.log.debug "registering task #{name}..."
  AvoDeploy::Deployment.instance.task_manager.add_task(name, options, &block)
end

Private Instance Methods

setup_config_defaults() click to toggle source

Sets up configuration defaults

@return [Hash] configuration defaults

# File lib/avodeploy/config.rb, line 125
def setup_config_defaults
  {
      :project_name => '',
      :scm => :git,
      :repo_url => '',
      :branch => :master,
      :stage => :production,
      :strategy => nil,
      :ignore_files => [],
      :log_level => Logger::WARN,
      :force_tag => false,
  }
end