Class: Ruby::Nginx::Commands::AddHostMapping
- Inherits:
-
TerminalCommand
- Object
- TerminalCommand
- Ruby::Nginx::Commands::AddHostMapping
- Defined in:
- lib/ruby/nginx/commands/add_host_mapping.rb
Instance Attribute Summary
Attributes inherited from TerminalCommand
#cmd, #error_type, #printer, #result, #user
Instance Method Summary collapse
-
#initialize(host, ip, sudo: false) ⇒ AddHostMapping
constructor
A new instance of AddHostMapping.
- #run ⇒ Object
Methods included from Helpers::SudoHelper
Methods included from Helpers::PromptHelper
Constructor Details
#initialize(host, ip, sudo: false) ⇒ AddHostMapping
Returns a new instance of AddHostMapping.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby/nginx/commands/add_host_mapping.rb', line 9 def initialize(host, ip, sudo: false) @host = host @ip = ip @sudo = sudo sudo_reason = "Allow sudo elevation to add \"#{host}\" to /etc/hosts?" super( cmd: "echo \"#{host_config}\" | #{sudoify("tee -a /etc/hosts", sudo, sudo_reason)}", raise: Ruby::Nginx::ConfigError ) end |
Instance Method Details
#run ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/ruby/nginx/commands/add_host_mapping.rb', line 21 def run super unless added? rescue Ruby::Nginx::ConfigError raise if @sudo # Elevate to sudo and try again. self.class.new(@host, @ip, sudo: true).run end |