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

Parameters:

  • key (Symbol)

    configuration key

Returns:

  • (mixed)

    configuration value

Raises:

  • (ArgumentError)


47
48
49
50
51
# File 'lib/avodeploy/config.rb', line 47

def get(key)
  raise ArgumentError, "key #{key} is not set" unless @config.has_key?(key)

  @config[key]
end

#merge(other_config) ⇒ Hash

Merges the configuration with another config hash

Parameters:

  • other_config (Hash)

    configuration hash

Returns:

  • (Hash)

    the merged hash



93
94
95
# File 'lib/avodeploy/config.rb', line 93

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

#set(key, value) ⇒ Object

Sets a configuration item

Parameters:

  • key (Symbol)

    configuration key

  • value (mixed)

    configuration value



39
40
41
# File 'lib/avodeploy/config.rb', line 39

def set(key, value)
  @config[key] = value
end

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

Defines a stage

Parameters:

  • name (Symbol)

    stage name

  • options (Hash) (defaults to: {})

    stage options

  • block (Block)

    the stage configuration



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/avodeploy/config.rb', line 67

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

Parameters:

  • name (Symbol)

    the deployment targets’ name

  • options (Hash) (defaults to: {})

    target options



85
86
87
# File 'lib/avodeploy/config.rb', line 85

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

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

Defines a task

Parameters:

  • name (Symbol)

    task name

  • options (Hash) (defaults to: {})

    task options

  • block (Block)

    the code to be executed when the task is started



58
59
60
# File 'lib/avodeploy/config.rb', line 58

def task(name, options = {}, &block)
  AvoDeploy::Deployment.instance.task_manager.add_task(name, options, &block)
end