Class: Hammerhead::Configuration
- Inherits:
-
Object
- Object
- Hammerhead::Configuration
- Defined in:
- lib/hammerhead/configuration.rb
Overview
:markup: markdown Represents the configuration for the hammerhead tool. It wraps the [tty-config](rubygems.org/gems/tty-config) gem.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#client_shortcut(shortcut) ⇒ Object
:category: clients Convenience method to obtain a configured
shortcut
. -
#client_shortcuts ⇒ Object
:category: clients Returns an Array of entries defined under
clients.shortcuts
. -
#clients_to_exclude ⇒ Object
:category: clients Returns an Array of client ids to be excluded from all operations.
-
#initialize ⇒ Configuration
constructor
Creates a new instance of TTY::Config, configured with filename ‘hammerhead.yml’ and to look for said file in the current working directory or in the user’s home directory.
-
#password ⇒ Object
:category: harvest Returns the Harvest
password
as defined in the configuration file. -
#subdomain ⇒ Object
:category: harvest Returns the Harvest
subdomain
as defined in the configuration file. -
#username ⇒ Object
:category: harvest Returns the Harvest
username
as defined in the configuration file. -
#validate! ⇒ Object
:category: validation Performs 2 important checks: 1) if the file exists and 2) if it contains the required harvest information.
Constructor Details
#initialize ⇒ Configuration
Creates a new instance of TTY::Config, configured with filename ‘hammerhead.yml’ and to look for said file in the current working directory or in the user’s home directory.
19 20 21 22 23 24 |
# File 'lib/hammerhead/configuration.rb', line 19 def initialize self.config = TTY::Config.new config.append_path Dir.pwd # look in current working directory config.append_path Dir.home # look in user home directory config.filename = File.basename configuration_filename, '.*' end |
Instance Attribute Details
#config ⇒ Object
:nodoc:
12 13 14 |
# File 'lib/hammerhead/configuration.rb', line 12 def config @config end |
Instance Method Details
#client_shortcut(shortcut) ⇒ Object
:category: clients Convenience method to obtain a configured shortcut
. Returns a Hash or nil
client_shortcut 'acme' => { id: 999999999, name: 'ACME Co, Inc' }
62 63 64 |
# File 'lib/hammerhead/configuration.rb', line 62 def client_shortcut shortcut client_shortcuts[shortcut] end |
#client_shortcuts ⇒ Object
:category: clients Returns an Array of entries defined under clients.shortcuts
70 71 72 |
# File 'lib/hammerhead/configuration.rb', line 70 def client_shortcuts config.fetch('clients.shortcuts', default: []) end |
#clients_to_exclude ⇒ Object
:category: clients Returns an Array of client ids to be excluded from all operations.
78 79 80 |
# File 'lib/hammerhead/configuration.rb', line 78 def clients_to_exclude config.fetch('clients.exclude', default: []) end |
#password ⇒ Object
:category: harvest Returns the Harvest password
as defined in the configuration file.
This configuration items is required.
32 33 34 |
# File 'lib/hammerhead/configuration.rb', line 32 def password harvest_configuration['password'] end |
#subdomain ⇒ Object
:category: harvest Returns the Harvest subdomain
as defined in the configuration file.
This configuration items is required.
42 43 44 |
# File 'lib/hammerhead/configuration.rb', line 42 def subdomain harvest_configuration['subdomain'] end |
#username ⇒ Object
:category: harvest Returns the Harvest username
as defined in the configuration file.
This configuration items is required.
52 53 54 |
# File 'lib/hammerhead/configuration.rb', line 52 def username harvest_configuration['username'] end |
#validate! ⇒ Object
:category: validation Performs 2 important checks: 1) if the file exists and 2) if it contains the required harvest information. If either of those fail this method raises an Hammerhead::Error.
88 89 90 91 |
# File 'lib/hammerhead/configuration.rb', line 88 def validate! load_configuration! validate_harvest_information end |