Class: Ruby::Nginx::Commands::SetupNginx
- Inherits:
-
TerminalCommand
- Object
- TerminalCommand
- Ruby::Nginx::Commands::SetupNginx
- Includes:
- Ruby::Nginx::Constants
- Defined in:
- lib/ruby/nginx/commands/setup_nginx.rb
Constant Summary collapse
- INCLUDE_STATEMENT =
"include #{File.(SERVERS_PATH)}/*;"- EXTERNAL_INCLUDE_STATEMENTS =
[ "include /etc/nginx/sites-enabled/\\*;", "include servers/\\*;" ]
Constants included from Ruby::Nginx::Constants
Ruby::Nginx::Constants::CONFIG_PATH, Ruby::Nginx::Constants::SERVERS_PATH
Instance Attribute Summary
Attributes inherited from TerminalCommand
#cmd, #error_type, #printer, #result, #user
Instance Method Summary collapse
-
#initialize(sudo: false) ⇒ SetupNginx
constructor
A new instance of SetupNginx.
- #run ⇒ Object
Methods included from Helpers::SudoHelper
Methods included from Helpers::PromptHelper
Constructor Details
#initialize(sudo: false) ⇒ SetupNginx
Returns a new instance of SetupNginx.
20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby/nginx/commands/setup_nginx.rb', line 20 def initialize(sudo: false) @sudo = sudo sudo_reason = "Allow sudo elevation to add \"#{INCLUDE_STATEMENT}\" to NGINX configuration file?" super( cmd: "echo \"#{new_config}\" | #{sudoify("tee #{config_file_path}", sudo, sudo_reason)}", raise: Ruby::Nginx::SetupError ) end |
Instance Method Details
#run ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/ruby/nginx/commands/setup_nginx.rb', line 30 def run super unless setup? rescue Ruby::Nginx::SetupError raise if @sudo # Elevate to sudo and try again. self.class.new(sudo: true).run end |