class Hammerhead::Configuration

Represents the configuration for the hammerhead tool. It wraps the tty-config gem.

Public Class Methods

new() click to toggle source

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.

# 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

Private Instance Methods

configuration_filename() click to toggle source
# File lib/hammerhead/configuration.rb, line 97
def configuration_filename
  'hammerhead.yml'
end
harvest_configuration() click to toggle source
# File lib/hammerhead/configuration.rb, line 101
def harvest_configuration
  config.fetch :harvest
end
load_configuration!() click to toggle source
# File lib/hammerhead/configuration.rb, line 105
def load_configuration!
  unless config.exist?
    raise Hammerhead::Error, "HarvestClient configuration file, '#{configuration_filename}' does not exist."
  end

  config.read
end
validate_harvest_information() click to toggle source
# File lib/hammerhead/configuration.rb, line 113
def validate_harvest_information
  configuration_missing_messages = []
  if harvest_configuration.nil?
    configuration_missing_messages << "'#{configuration_filename}' does not define harvest configuration."
  else
    if subdomain.nil?
      configuration_missing_messages << "'#{configuration_filename}' does not define harvest subdomain."
    end
    if username.nil?
      configuration_missing_messages << "'#{configuration_filename}' does not define harvest username."
    end
    if password.nil?
      configuration_missing_messages << "'#{configuration_filename}' does not define harvest password."
    end
  end
  raise Hammerhead::Error, configuration_missing_messages.join("\n") unless configuration_missing_messages.empty?
end

clients

↑ top

Public Instance Methods

client_shortcut(shortcut) click to toggle source

Convenience method to obtain a configured shortcut. Returns a Hash or nil

client_shortcut 'acme' => { id: 999999999, name: 'ACME Co, Inc' }
# File lib/hammerhead/configuration.rb, line 62
def client_shortcut shortcut
  client_shortcuts[shortcut]
end
client_shortcuts() click to toggle source

Returns an Array of entries defined under clients.shortcuts

# File lib/hammerhead/configuration.rb, line 70
def client_shortcuts
  config.fetch('clients.shortcuts', default: [])
end
clients_to_exclude() click to toggle source

Returns an Array of client ids to be excluded from all operations.

# File lib/hammerhead/configuration.rb, line 78
def clients_to_exclude
  config.fetch('clients.exclude', default: [])
end

harvest

↑ top

Public Instance Methods

password() click to toggle source

Returns the Harvest password as defined in the configuration file.

This configuration items is required.

# File lib/hammerhead/configuration.rb, line 32
def password
  harvest_configuration['password']
end
subdomain() click to toggle source

Returns the Harvest subdomain as defined in the configuration file.

This configuration items is required.

# File lib/hammerhead/configuration.rb, line 42
def subdomain
  harvest_configuration['subdomain']
end
username() click to toggle source

Returns the Harvest username as defined in the configuration file.

This configuration items is required.

# File lib/hammerhead/configuration.rb, line 52
def username
  harvest_configuration['username']
end

validation

↑ top

Public Instance Methods

validate!() click to toggle source

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.

# File lib/hammerhead/configuration.rb, line 88
def validate!
  load_configuration!
  validate_harvest_information
end