Class: BoringServices::Configuration
- Inherits:
-
Object
- Object
- BoringServices::Configuration
- Defined in:
- lib/boring_services/configuration.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Class Method Summary collapse
Instance Method Summary collapse
- #enabled_services ⇒ Object
- #forward_agent ⇒ Object
-
#initialize(config_path, environment) ⇒ Configuration
constructor
A new instance of Configuration.
- #secrets ⇒ Object
- #service_config(service_name) ⇒ Object
- #service_enabled?(service_name) ⇒ Boolean
- #services ⇒ Object
- #ssh_auth_methods ⇒ Object
- #ssh_key ⇒ Object
- #use_ssh_agent ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(config_path, environment) ⇒ Configuration
Returns a new instance of Configuration.
13 14 15 16 17 |
# File 'lib/boring_services/configuration.rb', line 13 def initialize(config_path, environment) @config_path = config_path @environment = environment.to_s @config = load_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/boring_services/configuration.rb', line 6 def config @config end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
6 7 8 |
# File 'lib/boring_services/configuration.rb', line 6 def environment @environment end |
Class Method Details
.load(config_path = 'config/services.yml', environment = nil) ⇒ Object
8 9 10 11 |
# File 'lib/boring_services/configuration.rb', line 8 def self.load(config_path = 'config/services.yml', environment = nil) env = environment || ENV['BORING_SERVICES_ENV'] || ENV['BORING_ENVIRONMENT'] || ENV['RAILS_ENV'] || 'production' new(config_path, env) end |
Instance Method Details
#enabled_services ⇒ Object
33 34 35 |
# File 'lib/boring_services/configuration.rb', line 33 def enabled_services services.reject { |s| s['enabled'] == false } end |
#forward_agent ⇒ Object
45 46 47 48 49 |
# File 'lib/boring_services/configuration.rb', line 45 def forward_agent return @config['forward_agent'] unless @config['forward_agent'].nil? true end |
#secrets ⇒ Object
61 62 63 |
# File 'lib/boring_services/configuration.rb', line 61 def secrets @config['secrets'] || {} end |
#service_config(service_name) ⇒ Object
19 20 21 22 |
# File 'lib/boring_services/configuration.rb', line 19 def service_config(service_name) services = @config['services'] || [] services.find { |s| s['name'] == service_name.to_s } end |
#service_enabled?(service_name) ⇒ Boolean
24 25 26 27 |
# File 'lib/boring_services/configuration.rb', line 24 def service_enabled?(service_name) service = service_config(service_name) service && service['enabled'] != false end |
#services ⇒ Object
29 30 31 |
# File 'lib/boring_services/configuration.rb', line 29 def services @config['services'] || [] end |
#ssh_auth_methods ⇒ Object
57 58 59 |
# File 'lib/boring_services/configuration.rb', line 57 def ssh_auth_methods (@config['ssh_auth_methods'] || ['publickey']).map(&:to_s) end |
#ssh_key ⇒ Object
41 42 43 |
# File 'lib/boring_services/configuration.rb', line 41 def ssh_key @config['ssh_key'] || '~/.ssh/id_rsa' end |
#use_ssh_agent ⇒ Object
51 52 53 54 55 |
# File 'lib/boring_services/configuration.rb', line 51 def use_ssh_agent return @config['use_ssh_agent'] unless @config['use_ssh_agent'].nil? false end |
#user ⇒ Object
37 38 39 |
# File 'lib/boring_services/configuration.rb', line 37 def user @config['user'] || 'ubuntu' end |