Class: DeploYML::Configuration
- Inherits:
-
Object
- Object
- DeploYML::Configuration
- Defined in:
- lib/deployml/configuration.rb
Overview
The Configuration class loads in the settings from a deploy.yml
file.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_SCM =
Default SCM to use
:rsync
- TASKS =
Valid task names
[ :setup, :update, :install, :migrate, :config, :start, :stop, :restart ]
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
The arbitrary commands to run after various tasks.
-
#before ⇒ Object
readonly
The arbitrary commands to run before various tasks.
-
#bundler ⇒ Object
readonly
Whether the project uses Bundler.
-
#debug ⇒ Object
Specifies whether to enable debugging.
-
#dest ⇒ Object
readonly
The destination URI to upload the project to.
-
#environment ⇒ Object
readonly
The environment to run the project in.
-
#framework ⇒ Object
readonly
The framework used by the project.
-
#orm ⇒ Object
readonly
The ORM used by the project.
-
#server_name ⇒ Object
readonly
The server run the deployed project under.
-
#server_options ⇒ Object
readonly
Options for the server.
-
#source ⇒ Object
readonly
The source URI of the project Git repository.
Instance Method Summary collapse
-
#each_dest {|dest| ... } ⇒ Enumerator
Iterates over each destination.
-
#initialize(config = {}) ⇒ Configuration
constructor
Creates a new Configuration using the given configuration.
-
#normalize(value) ⇒ Hash, ...
protected
Normalizes a value.
-
#normalize_array(array) ⇒ Array
protected
Normalizes an Array.
-
#normalize_hash(hash) ⇒ Hash{Symbol => Object}
protected
Converts all the keys of a Hash to Symbols.
-
#parse_address(address) ⇒ Addressable::URI
protected
Parses an address.
-
#parse_commands(command) ⇒ Array<String>
protected
Parses a command.
-
#parse_dest(dest) ⇒ Array<Addressable::URI>, Addressable::URI
protected
Parses the value for the
dest
setting. -
#parse_server(server) ⇒ Array<Symbol, Hash>
protected
Parses the value for the
server
setting.
Constructor Details
#initialize(config = {}) ⇒ Configuration
Creates a new DeploYML::Configuration using the given configuration.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/deployml/configuration.rb', line 92 def initialize(config={}) config = normalize_hash(config) @bundler = config.fetch(:bundler,false) @framework = case config[:framework] when 'rails', 'rails2', 'rails3' :rails when String, Symbol config[:framework].to_sym end @orm = if config[:orm] config[:orm].to_sym end @server_name, @server_options = parse_server(config[:server]) @source = config[:source] @dest = if config[:dest] parse_dest(config[:dest]) end @environment = if config[:environment] config[:environment].to_sym end @debug = config.fetch(:debug,false) @before = {} @after = {} TASKS.each do |task| if (config.has_key?(:before) && config[:before].has_key?(task)) @before[task] = parse_commands(config[:before][task]) end if (config.has_key?(:after) && config[:after].has_key?(task)) @after[task] = parse_commands(config[:after][task]) end end end |
Instance Attribute Details
#after ⇒ Object (readonly)
The arbitrary commands to run after various tasks
59 60 61 |
# File 'lib/deployml/configuration.rb', line 59 def after @after end |
#before ⇒ Object (readonly)
The arbitrary commands to run before various tasks
56 57 58 |
# File 'lib/deployml/configuration.rb', line 56 def before @before end |
#bundler ⇒ Object (readonly)
Whether the project uses Bundler.
41 42 43 |
# File 'lib/deployml/configuration.rb', line 41 def bundler @bundler end |
#debug ⇒ Object
Specifies whether to enable debugging.
53 54 55 |
# File 'lib/deployml/configuration.rb', line 53 def debug @debug end |
#dest ⇒ Object (readonly)
The destination URI to upload the project to.
38 39 40 |
# File 'lib/deployml/configuration.rb', line 38 def dest @dest end |
#environment ⇒ Object (readonly)
The environment to run the project in
50 51 52 |
# File 'lib/deployml/configuration.rb', line 50 def environment @environment end |
#framework ⇒ Object (readonly)
The framework used by the project
44 45 46 |
# File 'lib/deployml/configuration.rb', line 44 def framework @framework end |
#orm ⇒ Object (readonly)
The ORM used by the project
47 48 49 |
# File 'lib/deployml/configuration.rb', line 47 def orm @orm end |
#server_name ⇒ Object (readonly)
The server run the deployed project under
29 30 31 |
# File 'lib/deployml/configuration.rb', line 29 def server_name @server_name end |
#server_options ⇒ Object (readonly)
Options for the server
32 33 34 |
# File 'lib/deployml/configuration.rb', line 32 def @server_options end |
#source ⇒ Object (readonly)
The source URI of the project Git repository.
35 36 37 |
# File 'lib/deployml/configuration.rb', line 35 def source @source end |
Instance Method Details
#each_dest {|dest| ... } ⇒ Enumerator
Iterates over each destination.
149 150 151 152 153 154 155 156 157 |
# File 'lib/deployml/configuration.rb', line 149 def each_dest(&block) return enum_for(:each_dest) unless block_given? if @dest.kind_of?(Array) @dest.each(&block) elsif @dest yield @dest end end |
#normalize(value) ⇒ Hash, ... (protected)
Normalizes a value.
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/deployml/configuration.rb', line 206 def normalize(value) case value when Hash normalize_hash(value) when Array normalize_array(value) else value end end |
#normalize_array(array) ⇒ Array (protected)
Normalizes an Array.
172 173 174 |
# File 'lib/deployml/configuration.rb', line 172 def normalize_array(array) array.map { |value| normalize(value) } end |
#normalize_hash(hash) ⇒ Hash{Symbol => Object} (protected)
Converts all the keys of a Hash to Symbols.
185 186 187 188 189 190 191 192 193 |
# File 'lib/deployml/configuration.rb', line 185 def normalize_hash(hash) new_hash = {} hash.each do |key,value| new_hash[key.to_sym] = normalize(value) end return new_hash end |
#parse_address(address) ⇒ Addressable::URI (protected)
Parses an address.
260 261 262 263 264 265 266 267 268 269 |
# File 'lib/deployml/configuration.rb', line 260 def parse_address(address) case address when Hash Addressable::URI.new(address) when String Addressable::URI.parse(address) else raise(InvalidConfig,"invalid address: #{address.inspect}",caller) end end |
#parse_commands(command) ⇒ Array<String> (protected)
Parses a command.
305 306 307 308 309 310 311 312 313 314 |
# File 'lib/deployml/configuration.rb', line 305 def parse_commands(command) case command when Array command.map { |line| line.to_s } when String command.enum_for(:each_line).map { |line| line.chomp } else raise(InvalidConfig,"commands must be an Array or a String") end end |
#parse_dest(dest) ⇒ Array<Addressable::URI>, Addressable::URI (protected)
Parses the value for the dest
setting.
282 283 284 285 286 287 288 289 |
# File 'lib/deployml/configuration.rb', line 282 def parse_dest(dest) case dest when Array dest.map { |address| parse_address(address) } else parse_address(dest) end end |
#parse_server(server) ⇒ Array<Symbol, Hash> (protected)
Parses the value for the server
setting.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/deployml/configuration.rb', line 225 def parse_server(server) name = nil = {} case server when Symbol, String name = server.to_sym when Hash unless server.has_key?(:name) raise(MissingOption,"the 'server' option must contain a 'name' option for which server to use",caller) end if server.has_key?(:name) name = server[:name].to_sym end if server.has_key?(:options) .merge!(server[:options]) end end return [name, ] end |