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.



6
7
8
# File 'lib/mrsk/commander.rb', line 6

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.



4
5
6
# File 'lib/mrsk/commander.rb', line 4

def config_file
  @config_file
end

#destinationObject

Returns the value of attribute destination.



4
5
6
# File 'lib/mrsk/commander.rb', line 4

def destination
  @destination
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



17
18
19
# File 'lib/mrsk/commander.rb', line 17

def specific_hosts
  @specific_hosts
end

#verbosityObject

Returns the value of attribute verbosity.



4
5
6
# File 'lib/mrsk/commander.rb', line 4

def verbosity
  @verbosity
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/mrsk/commander.rb', line 4

def version
  @version
end

Instance Method Details

#accessory(name) ⇒ Object



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

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

#accessory_hostsObject



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

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

#accessory_namesObject



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

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

#appObject



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

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

#auditorObject



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

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

#builderObject



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

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

#configObject



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

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

#healthcheckObject



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

def healthcheck
  @healthcheck ||= Mrsk::Commands::Healthcheck.new(config)
end

#hostsObject



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

def hosts
  specific_hosts || config.all_hosts
end

#primary_hostObject



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

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

#pruneObject



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

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

#registryObject



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

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

#resetObject

Test-induced damage!



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

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

#specific_primary!Object



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

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

#specific_roles=(role_names) ⇒ Object



23
24
25
# File 'lib/mrsk/commander.rb', line 23

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



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

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

#traefik_hostsObject



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

def traefik_hosts
  specific_hosts || config.traefik_hosts
end

#with_verbosity(level) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/mrsk/commander.rb', line 81

def with_verbosity(level)
  old_level = self.verbosity

  self.verbosity = level
  SSHKit.config.output_verbosity = level

  yield
ensure
  self.verbosity = old_level
  SSHKit.config.output_verbosity = old_level
end