Class: Factor::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/base.rb

Overview

Base command with common methods used by all commands

Direct Known Subclasses

RegistryCommand, RunCommand, WorkflowCommand

Constant Summary collapse

DEFAULT_FILENAME =
{
  connectors:   File.expand_path('./connectors.yml'),
  credentials:  File.expand_path('./credentials.yml')
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



20
21
22
# File 'lib/commands/base.rb', line 20

def initialize
  @logger = Factor::Log::BasicLogger.new
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/commands/base.rb', line 13

def logger
  @logger
end

Instance Method Details

#load_config(options = {}) ⇒ Object



24
25
26
27
# File 'lib/commands/base.rb', line 24

def load_config(options = {})
  load_config_data :credentials, options
  load_config_data :connectors, options
end

#save_config(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/commands/base.rb', line 29

def save_config(options={})
  credentials_relative_path = options[:credentials] || DEFAULT_FILENAME[:credentials]
  credentials_absolute_path = File.expand_path(credentials_relative_path)
  connectors_relative_path = options[:connectors] || DEFAULT_FILENAME[:connectors]
  connectors_absolute_path = File.expand_path(connectors_relative_path)

  connectors  = Hash[stringify(configatron.connectors.to_h).sort]
  credentials = Hash[stringify(configatron.credentials.to_h).sort]

  File.write(connectors_absolute_path,YAML.dump(connectors))
  File.write(credentials_absolute_path,YAML.dump(credentials))
end