class Invoker::Power::Setup

Attributes

port_finder[RW]
tld[RW]

Public Class Methods

install(tld) click to toggle source
# 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() click to toggle source
# File lib/invoker/power/setup.rb, line 19
def self.installer_klass
  if Invoker.darwin?
    Invoker::Power::OsxSetup
  else
    Invoker::Power::LinuxSetup
  end
end
new(tld) click to toggle source
# File lib/invoker/power/setup.rb, line 27
def initialize(tld)
  if tld !~ /^[a-z]+$/
    Invoker::Logger.puts("Please specify valid tld".color(:red))
    exit(1)
  end
  self.tld = tld
end
uninstall() click to toggle source
# 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

Public Instance Methods

build_power_config() click to toggle source

Builds and returns power config hash. Override this method in subclasses if necessary.

# 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?() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/invoker/power/setup.rb, line 44
def drop_to_normal_user
  EventMachine.set_effective_user(ENV["SUDO_USER"])
end
find_open_ports() click to toggle source
# File lib/invoker/power/setup.rb, line 48
def find_open_ports
  port_finder.find_ports()
end
install() click to toggle source
# 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.".color(:red))
  end
  self
end
remove_resolver_file() click to toggle source
# 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".color(:red))
    raise
  end
end
safe_remove_file(file) click to toggle source
# File lib/invoker/power/setup.rb, line 85
def safe_remove_file(file)
  File.delete(file) if File.exists?(file)
end