Class: AvoDeploy::Config
- Inherits:
-
Object
- Object
- AvoDeploy::Config
- Defined in:
- lib/avodeploy/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#loaded_stage ⇒ Object
readonly
Returns the value of attribute loaded_stage.
-
#stages ⇒ Object
readonly
Returns the value of attribute stages.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Instance Method Summary collapse
-
#get(key) ⇒ mixed
Returns a configuration item if set.
-
#inherit_strategy(strategy) ⇒ Object
Loads a strategy.
-
#initialize ⇒ Config
constructor
Intializes the config object.
-
#merge(other_config) ⇒ Hash
Merges the configuration with another config hash.
-
#set(key, value) ⇒ Object
Sets a configuration item.
-
#setup_stage(name, options = {}, &block) ⇒ Object
Defines a stage.
-
#target(name, options = {}) ⇒ Object
Defines a deployment target.
-
#task(name, options = {}, &block) ⇒ Object
Defines a task.
Constructor Details
#initialize ⇒ Config
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
22 23 24 |
# File 'lib/avodeploy/config.rb', line 22 def config @config end |
#loaded_stage ⇒ Object (readonly)
Returns the value of attribute loaded_stage.
25 26 27 |
# File 'lib/avodeploy/config.rb', line 25 def loaded_stage @loaded_stage end |
#stages ⇒ Object (readonly)
Returns the value of attribute stages.
23 24 25 |
# File 'lib/avodeploy/config.rb', line 23 def stages @stages end |
#targets ⇒ Object (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
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, = {}, &block) stages[name] = '' if .has_key?(:desc) stages[name] = [: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, = {}) @targets[name] = AvoDeploy::Target.new(name, ) end |
#task(name, options = {}, &block) ⇒ Object
Defines a task
81 82 83 84 |
# File 'lib/avodeploy/config.rb', line 81 def task(name, = {}, &block) AvoDeploy::Deployment.instance.log.debug "registering task #{name}..." AvoDeploy::Deployment.instance.task_manager.add_task(name, , &block) end |