Class: Fulmar::Domain::Model::Configuration
- Inherits:
-
Object
- Object
- Fulmar::Domain::Model::Configuration
- Defined in:
- lib/fulmar/domain/model/configuration.rb
Overview
Loads and prepares the configuration from the yaml file
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
-
#[](id) ⇒ Object
Allow access of configuration via array/hash access methods (read access).
-
#[]=(id, value) ⇒ Object
Allow access of configuration via array/hash access methods (write access).
-
#dependencies(env = nil) ⇒ Object
Handle dependencies.
-
#each ⇒ Object
Allows iterating over all targets from all configured environments.
-
#hosts ⇒ Object
Allow access to host list.
-
#initialize(data, base_path = '', debug = false) ⇒ Configuration
constructor
A new instance of Configuration.
-
#key?(key) ⇒ Boolean
Checks if a configuration key exists in one of the targets.
-
#merge(other) ⇒ Object
Merge another configuration into the currently active one Useful for supplying a default configuration, as values are not overwritten.
- #plugins ⇒ Object
-
#project ⇒ Object
Return the project.
-
#ready? ⇒ Boolean
Checks if environment and target are set.
-
#set(environment, target = nil) ⇒ Object
Set the environment and target in one call.
-
#ssh_user_and_host ⇒ Object
Return the combined user and host.
Constructor Details
#initialize(data, base_path = '', debug = false) ⇒ Configuration
Returns a new instance of Configuration.
16 17 18 19 20 21 |
# File 'lib/fulmar/domain/model/configuration.rb', line 16 def initialize(data, base_path = '', debug = false) @data = data @base_path = base_path @debug = debug prepare_data end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
13 14 15 |
# File 'lib/fulmar/domain/model/configuration.rb', line 13 def base_path @base_path end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
14 15 16 |
# File 'lib/fulmar/domain/model/configuration.rb', line 14 def debug @debug end |
#environment ⇒ Object
Returns the value of attribute environment.
13 14 15 |
# File 'lib/fulmar/domain/model/configuration.rb', line 13 def environment @environment end |
#target ⇒ Object
Returns the value of attribute target.
13 14 15 |
# File 'lib/fulmar/domain/model/configuration.rb', line 13 def target @target end |
Instance Method Details
#[](id) ⇒ Object
Allow access of configuration via array/hash access methods (read access)
24 25 26 |
# File 'lib/fulmar/domain/model/configuration.rb', line 24 def [](id) ready? ? @data[:environments][@environment][@target][id] : nil end |
#[]=(id, value) ⇒ Object
Allow access of configuration via array/hash access methods (write access)
29 30 31 32 33 34 35 36 |
# File 'lib/fulmar/domain/model/configuration.rb', line 29 def []=(id, value) if ready? @data[:environments][@environment][@target][id] = value else raise 'Environment or target not set. Please set both variables via configuration.environment = \'xxx\' / '\ 'configuration.target = \'yyy\'' end end |
#dependencies(env = nil) ⇒ Object
Refactor this to work with the dependencies plugin
Handle dependencies
85 86 87 88 89 90 91 |
# File 'lib/fulmar/domain/model/configuration.rb', line 85 def dependencies(env = nil) if env.nil? || !@data[:dependencies].key?(env) @data[:dependencies][:all] else @data[:dependencies][:all].deep_merge(@data[:dependencies][env]) end end |
#each ⇒ Object
Allows iterating over all targets from all configured environments
69 70 71 72 73 74 75 |
# File 'lib/fulmar/domain/model/configuration.rb', line 69 def each @data[:environments].each_key do |env| @data[:environments][env].each_pair do |target, data| yield(env, target, data) end end end |
#hosts ⇒ Object
Allow access to host list
94 95 96 |
# File 'lib/fulmar/domain/model/configuration.rb', line 94 def hosts @data[:hosts] end |
#key?(key) ⇒ Boolean
Checks if a configuration key exists in one of the targets
99 100 101 |
# File 'lib/fulmar/domain/model/configuration.rb', line 99 def key?(key) ready? ? @data[:environments][@environment][@target].key?(key) : false end |
#merge(other) ⇒ Object
Merge another configuration into the currently active one Useful for supplying a default configuration, as values are not overwritten. Hashes are merged.
107 108 109 110 |
# File 'lib/fulmar/domain/model/configuration.rb', line 107 def merge(other) return unless @environment && @target @data[:environments][@environment][@target] = other.deep_merge(@data[:environments][@environment][@target]) end |
#plugins ⇒ Object
64 65 66 |
# File 'lib/fulmar/domain/model/configuration.rb', line 64 def plugins @data[:plugins] || {} end |
#project ⇒ Object
Return the project
60 61 62 |
# File 'lib/fulmar/domain/model/configuration.rb', line 60 def project @project ||= Fulmar::Domain::Model::Project.new(@data[:project]) end |
#ready? ⇒ Boolean
Checks if environment and target are set
52 53 54 55 56 57 |
# File 'lib/fulmar/domain/model/configuration.rb', line 52 def ready? return false if @environment.nil? || @target.nil? raise 'Environment is invalid' if @data[:environments][@environment].nil? raise 'Target is invalid' if @data[:environments][@environment][@target].nil? true end |
#set(environment, target = nil) ⇒ Object
Set the environment and target in one call
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fulmar/domain/model/configuration.rb', line 39 def set(environment, target = nil) # For convenience, allow something like "environment:target" as string if environment.class == String fields = environment.split(':') @environment = fields.first.to_sym @target = fields.size > 1 ? fields[1].to_sym : nil else @environment = environment @target = target unless target.nil? end end |
#ssh_user_and_host ⇒ Object
Is there another way to do this?
Return the combined user and host
79 80 81 |
# File 'lib/fulmar/domain/model/configuration.rb', line 79 def ssh_user_and_host self[:user].blank? ? self[:hostname] : self[:user] + '@' + self[:hostname] end |