Class: Ruby::Nginx::Commands::ValidateNginxConfig

Inherits:
TerminalCommand show all
Defined in:
lib/ruby/nginx/commands/validate_nginx_config.rb

Instance Attribute Summary

Attributes inherited from TerminalCommand

#cmd, #error_type, #printer, #result, #user

Instance Method Summary collapse

Methods included from Helpers::SudoHelper

#sudoify

Methods included from Helpers::PromptHelper

#yes?

Constructor Details

#initialize(sudo: false) ⇒ ValidateNginxConfig

Returns a new instance of ValidateNginxConfig.



9
10
11
12
13
14
# File 'lib/ruby/nginx/commands/validate_nginx_config.rb', line 9

def initialize(sudo: false)
  @sudo = sudo
  sudo_reason = "Allow sudo elevation to validate NGINX config?"

  super(cmd: sudoify("nginx -t", sudo, sudo_reason), raise: Ruby::Nginx::ConfigError)
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
# File 'lib/ruby/nginx/commands/validate_nginx_config.rb', line 16

def run
  super
rescue Ruby::Nginx::ConfigError
  raise if @sudo

  # Elevate to sudo and try again.
  self.class.new(sudo: true).run
end