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

Registry, Workflow

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

Instance Attribute Details

#destination_streamObject

Returns the value of attribute destination_stream.



17
18
19
# File 'lib/commands/base.rb', line 17

def destination_stream
  @destination_stream
end

Instance Method Details

#error(options = {}) ⇒ Object



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

def error(options = {})
  log_line :error, options
end

#exception(message, exception) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/commands/base.rb', line 35

def exception(message, exception)
  error 'message' => message
  error 'message' => "  #{exception.message}"
  exception.backtrace.each do |line|
    error 'message' => "    #{line}"
  end
end

#info(options = {}) ⇒ Object



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

def info(options = {})
  log_line :info, options
end

#load_config(options = {}) ⇒ Object



43
44
45
46
# File 'lib/commands/base.rb', line 43

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

#save_config(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/commands/base.rb', line 48

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

#success(options = {}) ⇒ Object



31
32
33
# File 'lib/commands/base.rb', line 31

def success(options = {})
  log_line :success, options
end

#warn(options = {}) ⇒ Object



27
28
29
# File 'lib/commands/base.rb', line 27

def warn(options = {})
  log_line :warn, options
end