Class: AvoDeploy::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Intializes the config object



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

def initialize
  @config = setup_config_defaults
  @stages = {}
  @targets = {}
  @loaded_stage = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/avodeploy/config.rb', line 22

def config
  @config
end

#loaded_stageObject (readonly)

Returns the value of attribute loaded_stage.



25
26
27
# File 'lib/avodeploy/config.rb', line 25

def loaded_stage
  @loaded_stage
end

#stagesObject (readonly)

Returns the value of attribute stages.



23
24
25
# File 'lib/avodeploy/config.rb', line 23

def stages
  @stages
end

#targetsObject (readonly)

Returns the value of attribute targets.



24
25
26
# File 'lib/avodeploy/config.rb', line 24

def targets
  @targets
end

Instance Method Details

#get(key) ⇒ mixed

Returns a configuration item if set

Raises:

  • (ArgumentError)


70
71
72
73
74
# 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) ⇒ Object

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.



54
55
56
57
58
59
60
61
62
63
64
# 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) ⇒ Hash

Merges the configuration with another config hash



117
118
119
# File 'lib/avodeploy/config.rb', line 117

def merge(other_config)
  @config.merge(other_config)
end

#set(key, value) ⇒ Object

Sets a configuration item



39
40
41
42
43
44
45
46
47
# 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) ⇒ Object

Defines a stage



91
92
93
94
95
96
97
98
99
100
101
102
103
# 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 = {}) ⇒ Object

Defines a deployment target



109
110
111
# File 'lib/avodeploy/config.rb', line 109

def target(name, options = {})
  @targets[name] = AvoDeploy::Target.new(name, options)
end

#task(name, options = {}, &block) ⇒ Object

Defines a task



81
82
83
84
# 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