Class: Mrsk::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/mrsk/commander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file: nil, destination: nil, verbosity: :info) ⇒ Commander

Returns a new instance of Commander.



15
16
17
# File 'lib/mrsk/commander.rb', line 15

def initialize(config_file: nil, destination: nil, verbosity: :info)
  @config_file, @destination, @verbosity = config_file, destination, verbosity
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



13
14
15
# File 'lib/mrsk/commander.rb', line 13

def config_file
  @config_file
end

#destinationObject

Returns the value of attribute destination.



13
14
15
# File 'lib/mrsk/commander.rb', line 13

def destination
  @destination
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



26
27
28
# File 'lib/mrsk/commander.rb', line 26

def specific_hosts
  @specific_hosts
end

#verbosityObject

Returns the value of attribute verbosity.



13
14
15
# File 'lib/mrsk/commander.rb', line 13

def verbosity
  @verbosity
end

#versionObject

Returns the value of attribute version.



13
14
15
# File 'lib/mrsk/commander.rb', line 13

def version
  @version
end

Instance Method Details

#accessory(name) ⇒ Object



77
78
79
# File 'lib/mrsk/commander.rb', line 77

def accessory(name)
  Mrsk::Commands::Accessory.new(config, name: name)
end

#accessory_hostsObject



48
49
50
# File 'lib/mrsk/commander.rb', line 48

def accessory_hosts
  specific_hosts || config.accessories.collect(&:host)
end

#accessory_namesObject



52
53
54
# File 'lib/mrsk/commander.rb', line 52

def accessory_names
  config.accessories&.collect(&:name) || []
end

#appObject



57
58
59
# File 'lib/mrsk/commander.rb', line 57

def app
  @app ||= Mrsk::Commands::App.new(config)
end

#auditorObject



81
82
83
# File 'lib/mrsk/commander.rb', line 81

def auditor
  @auditor ||= Mrsk::Commands::Auditor.new(config)
end

#builderObject



61
62
63
# File 'lib/mrsk/commander.rb', line 61

def builder
  @builder ||= Mrsk::Commands::Builder.new(config)
end

#configObject



19
20
21
22
23
24
# File 'lib/mrsk/commander.rb', line 19

def config
  @config ||= \
    Mrsk::Configuration
      .create_from(config_file, destination: destination, version: cascading_version)
      .tap { |config| configure_sshkit_with(config) }
end

#hostsObject



40
41
42
# File 'lib/mrsk/commander.rb', line 40

def hosts
  specific_hosts || config.all_hosts
end

#primary_hostObject



36
37
38
# File 'lib/mrsk/commander.rb', line 36

def primary_host
  specific_hosts&.sole || config.primary_web_host
end

#pruneObject



73
74
75
# File 'lib/mrsk/commander.rb', line 73

def prune
  @prune ||= Mrsk::Commands::Prune.new(config)
end

#registryObject



69
70
71
# File 'lib/mrsk/commander.rb', line 69

def registry
  @registry ||= Mrsk::Commands::Registry.new(config)
end

#resetObject

Test-induced damage!



95
96
97
98
99
# File 'lib/mrsk/commander.rb', line 95

def reset
  @config = @config_file = @destination = @version = nil
  @app = @builder = @traefik = @registry = @prune = @auditor = nil
  @verbosity = :info
end

#specific_primary!Object



28
29
30
# File 'lib/mrsk/commander.rb', line 28

def specific_primary!
  self.specific_hosts = [ config.primary_web_host ]
end

#specific_roles=(role_names) ⇒ Object



32
33
34
# File 'lib/mrsk/commander.rb', line 32

def specific_roles=(role_names)
  self.specific_hosts = config.roles.select { |r| role_names.include?(r.name) }.flat_map(&:hosts) if role_names.present?
end

#traefikObject



65
66
67
# File 'lib/mrsk/commander.rb', line 65

def traefik
  @traefik ||= Mrsk::Commands::Traefik.new(config)
end

#traefik_hostsObject



44
45
46
# File 'lib/mrsk/commander.rb', line 44

def traefik_hosts
  specific_hosts || config.traefik_hosts
end

#with_verbosity(level) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/mrsk/commander.rb', line 86

def with_verbosity(level) 
  old_level = SSHKit.config.output_verbosity
  SSHKit.config.output_verbosity = level
  yield
ensure
  SSHKit.config.output_verbosity = old_level
end