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
21 22 23 24 25 26 27 |
# File 'lib/invoker/power/setup.rb', line 21 def self.installer_klass if Invoker.darwin? Invoker::Power::OsxSetup else Invoker::Power::LinuxSetup end end |
.uninstall ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/invoker/power/setup.rb', line 13 def self.uninstall if Invoker::Power::Config.has_config? power_config = Invoker::Power::Config.load_config selected_installer_klass = installer_klass selected_installer_klass.new(power_config.tld).uninstall_invoker end end |
Instance Method Details
#build_power_config ⇒ Object
Builds and returns power config hash. Override this method in subclasses if necessary.
69 70 71 72 73 74 75 76 |
# File 'lib/invoker/power/setup.rb', line 69 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
58 59 60 |
# File 'lib/invoker/power/setup.rb', line 58 def check_if_setup_can_run? !File.exist?(Invoker::Power::Config.config_file) end |
#create_config_file ⇒ Object
62 63 64 65 66 |
# File 'lib/invoker/power/setup.rb', line 62 def create_config_file Invoker.setup_config_location config = build_power_config Invoker::Power::Config.create(config) end |
#drop_to_normal_user ⇒ Object
46 47 48 |
# File 'lib/invoker/power/setup.rb', line 46 def drop_to_normal_user EventMachine.set_effective_user(ENV["SUDO_USER"]) end |
#find_open_ports ⇒ Object
50 51 52 |
# File 'lib/invoker/power/setup.rb', line 50 def find_open_ports port_finder.find_ports() end |
#install ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/invoker/power/setup.rb', line 37 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
78 79 80 81 82 83 84 85 86 |
# File 'lib/invoker/power/setup.rb', line 78 def remove_resolver_file return if resolver_file.nil? 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
88 89 90 |
# File 'lib/invoker/power/setup.rb', line 88 def safe_remove_file(file) File.delete(file) if File.exist?(file) end |