Class: Avocado::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Intializes the config object



27
28
29
30
31
# File 'lib/avocado/config.rb', line 27

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#stagesObject (readonly)

Returns the value of attribute stages.



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

def stages
  @stages
end

#targetsObject (readonly)

Returns the value of attribute targets.



24
25
26
# File 'lib/avocado/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)


45
46
47
48
49
# File 'lib/avocado/config.rb', line 45

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



87
88
89
# File 'lib/avocado/config.rb', line 87

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



37
38
39
# File 'lib/avocado/config.rb', line 37

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



65
66
67
68
69
70
71
72
73
# File 'lib/avocado/config.rb', line 65

def setup_stage(name, options = {}, &block)
  if options.has_key?(:desc)
    stages[name] =  options[:desc]
  end

  if name == get(:stage)
    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



79
80
81
# File 'lib/avocado/config.rb', line 79

def target(name, options = {})
  @targets[name] = Avocado::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



56
57
58
# File 'lib/avocado/config.rb', line 56

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