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, verbose: false) ⇒ Commander

Returns a new instance of Commander.



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

def initialize(config_file: nil, destination: nil, verbose: false)
  @config_file, @destination, @verbose = config_file, destination, verbose
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



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

def config_file
  @config_file
end

#destinationObject

Returns the value of attribute destination.



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

def destination
  @destination
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



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

def specific_hosts
  @specific_hosts
end

#verboseObject

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#accessory(name) ⇒ Object



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

def accessory(name)
  config.accessories.detect { |a| a.name == name }
end

#accessory_hostsObject



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

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

#accessory_namesObject



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

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

#appObject



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

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

#builderObject



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

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

#configObject



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

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

#hostsObject



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

def hosts
  specific_hosts || config.all_hosts
end

#primary_hostObject



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

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

#pruneObject



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

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

#registryObject



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

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

#specific_primary!Object



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

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

#specific_roles=(role_names) ⇒ Object



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

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



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

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

#traefik_hostsObject



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

def traefik_hosts
  specific_hosts || config.traefik_hosts
end

#verbosity(level) ⇒ Object



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

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