Class: Invoker::Power::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/invoker/power/setup.rb

Direct Known Subclasses

LinuxSetup, OsxSetup

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tld) ⇒ Setup

Returns a new instance of Setup.



29
30
31
32
33
34
35
# File 'lib/invoker/power/setup.rb', line 29

def initialize(tld)
  if tld !~ /^[a-z]+$/
    Invoker::Logger.puts("Please specify valid tld".colorize(:red))
    exit(1)
  end
  self.tld = tld
end

Instance Attribute Details

#port_finderObject

Returns the value of attribute port_finder.



6
7
8
# File 'lib/invoker/power/setup.rb', line 6

def port_finder
  @port_finder
end

#tldObject

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_klassObject



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

.uninstallObject



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_configObject

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

Returns:

  • (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_fileObject



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_userObject



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_portsObject



50
51
52
# File 'lib/invoker/power/setup.rb', line 50

def find_open_ports
  port_finder.find_ports()
end

#installObject



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_fileObject



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