Class: Invoker::Power::Setup
- Inherits:
-
Object
- Object
- Invoker::Power::Setup
- Defined in:
- lib/invoker/power/setup.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#port_finder ⇒ Object
Returns the value of attribute port_finder.
-
#tld ⇒ Object
Returns the value of attribute tld.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_power_config ⇒ Object
Builds and returns power config hash.
- #check_if_setup_can_run? ⇒ Boolean
- #create_config_file ⇒ Object
- #drop_to_normal_user ⇒ Object
- #find_open_ports ⇒ Object
-
#initialize(tld) ⇒ Setup
constructor
A new instance of Setup.
- #install ⇒ Object
- #remove_resolver_file ⇒ Object
- #safe_remove_file(file) ⇒ Object
Constructor Details
Instance Attribute Details
#port_finder ⇒ Object
Returns the value of attribute port_finder.
6 7 8 |
# File 'lib/invoker/power/setup.rb', line 6 def port_finder @port_finder end |
#tld ⇒ Object
Returns the value of attribute tld.
6 7 8 |
# File 'lib/invoker/power/setup.rb', line 6 def tld @tld end |
Class Method Details
.install(tld) ⇒ Object
8 9 10 11 |
# File 'lib/invoker/power/setup.rb', line 8 def self.install(tld) selected_installer_klass = installer_klass selected_installer_klass.new(tld).install end |
.installer_klass ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/invoker/power/setup.rb', line 19 def self.installer_klass if Invoker.darwin? Invoker::Power::OsxSetup else Invoker::Power::LinuxSetup end end |
.uninstall ⇒ Object
13 14 15 16 17 |
# File 'lib/invoker/power/setup.rb', line 13 def self.uninstall power_config = Invoker::Power::Config.load_config selected_installer_klass = installer_klass selected_installer_klass.new(power_config.tld).uninstall_invoker end |
Instance Method Details
#build_power_config ⇒ Object
Builds and returns power config hash. Override this method in subclasses if necessary.
67 68 69 70 71 72 73 74 |
# File 'lib/invoker/power/setup.rb', line 67 def build_power_config config = { http_port: port_finder.http_port, https_port: port_finder.https_port, tld: tld } config end |
#check_if_setup_can_run? ⇒ Boolean
56 57 58 |
# File 'lib/invoker/power/setup.rb', line 56 def check_if_setup_can_run? !File.exists?(Invoker::Power::Config.config_file) end |
#create_config_file ⇒ Object
60 61 62 63 64 |
# File 'lib/invoker/power/setup.rb', line 60 def create_config_file Invoker.setup_config_location config = build_power_config Invoker::Power::Config.create(config) end |
#drop_to_normal_user ⇒ Object
44 45 46 |
# File 'lib/invoker/power/setup.rb', line 44 def drop_to_normal_user EventMachine.set_effective_user(ENV["SUDO_USER"]) end |
#find_open_ports ⇒ Object
48 49 50 |
# File 'lib/invoker/power/setup.rb', line 48 def find_open_ports port_finder.find_ports() end |
#install ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/invoker/power/setup.rb', line 35 def install if check_if_setup_can_run? setup_invoker else Invoker::Logger.puts("The setup has been already run.".colorize(:red)) end self end |
#remove_resolver_file ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/invoker/power/setup.rb', line 76 def remove_resolver_file begin safe_remove_file(resolver_file) rescue Errno::EACCES Invoker::Logger.puts("Running uninstall requires root access, please rerun it with sudo".colorize(:red)) raise end end |
#safe_remove_file(file) ⇒ Object
85 86 87 |
# File 'lib/invoker/power/setup.rb', line 85 def safe_remove_file(file) File.delete(file) if File.exists?(file) end |