Module: Anvil::ConfigurationReader

Included in:
App::Deploy, App::Env, App::HostDeployer, App::HostInstaller, App::HostScaler, App::Install, App::Scale
Defined in:
lib/anvil/configuration_reader.rb

Overview

A set of utility methods for reading configuration data It expects the implemneting class to have a ‘configuration` method

Instance Method Summary collapse

Instance Method Details

#configuration_for(hostname) ⇒ Object



23
24
25
26
# File 'lib/anvil/configuration_reader.rb', line 23

def configuration_for hostname
  host_config = configuration["hosts"].find { |host_data| host_data.key?(hostname) ? host_data[hostname] : nil }
  host_config&.fetch(hostname)
end

#configuration_for_appObject



15
16
17
# File 'lib/anvil/configuration_reader.rb', line 15

def configuration_for_app
  configuration["app"]
end

#environment_for(hostname) ⇒ Object



28
29
30
# File 'lib/anvil/configuration_reader.rb', line 28

def environment_for hostname
  configuration_for(hostname)&.fetch "environment", []
end

#environment_for_appObject



19
20
21
# File 'lib/anvil/configuration_reader.rb', line 19

def environment_for_app
  configuration_for_app.fetch "environment", []
end

#hostsObject



7
8
9
# File 'lib/anvil/configuration_reader.rb', line 7

def hosts
  configuration["hosts"].collect { |host_data| host_data.keys }.flatten
end

#user_for(hostname) ⇒ Object



32
33
34
# File 'lib/anvil/configuration_reader.rb', line 32

def user_for hostname
  configuration_for(hostname)&.fetch "user", nil
end

#validate(hostname) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
# File 'lib/anvil/configuration_reader.rb', line 11

def validate hostname
  raise ArgumentError.new("Host #{hostname} is not in the configuration hosts list") unless hosts.include? hostname
end