Class: Invoker::Runner

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

Class Method Summary collapse

Class Method Details

.add_command(selected_command) ⇒ Object



53
54
55
56
57
58
# File 'lib/invoker/runner.rb', line 53

def self.add_command(selected_command)
  Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
    socket.puts("add #{selected_command.command_key}")
    socket.flush()
  end
end

.list_commands(selected_command) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/invoker/runner.rb', line 74

def self.list_commands(selected_command)
  Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) {|sock|
    sock.puts("list")
    data = sock.gets()
    Invoker::ProcessPrinter.print_table(data)
  }
end

.refresh_command(selected_command) ⇒ Object



67
68
69
70
71
72
# File 'lib/invoker/runner.rb', line 67

def self.refresh_command(selected_command)
  Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
    socket.puts("reload #{selected_command.command_key} #{selected_command.signal}")
    socket.flush()
  end
end

.remove_command(selected_command) ⇒ Object



60
61
62
63
64
65
# File 'lib/invoker/runner.rb', line 60

def self.remove_command(selected_command)
  Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
    socket.puts("remove #{selected_command.command_key} #{selected_command.signal}")
    socket.flush()
  end
end

.run(args) ⇒ Object



7
8
9
10
11
12
# File 'lib/invoker/runner.rb', line 7

def self.run(args)
  selected_command = Invoker::Parsers::OptionParser.parse(args)
  if selected_command
    run_command(selected_command)
  end
end

.run_command(selected_command) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/invoker/runner.rb', line 14

def self.run_command(selected_command)
  return unless selected_command
  case selected_command.command
  when 'setup'
    setup_pow(selected_command)
  when 'uninstall'
    uninstall_pow(selected_command)
  when 'start'
    start_server(selected_command)
  when 'add'
    add_command(selected_command)
  when 'reload'
    refresh_command(selected_command)
  when 'list'
    list_commands(selected_command)
  when 'remove'
    remove_command(selected_command)
  else
    Invoker::Logger.puts "Invalid command"
  end
end

.setup_pow(selected_command) ⇒ Object



36
37
38
# File 'lib/invoker/runner.rb', line 36

def self.setup_pow(selected_command)
  Invoker::Power::Setup.install()
end

.start_server(selected_command) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/invoker/runner.rb', line 44

def self.start_server(selected_command)
  config = Invoker::Parsers::Config.new(selected_command.file, selected_command.port)
  Invoker.const_set(:CONFIG, config)
  warn_about_terminal_notifier()
  commander = Invoker::Commander.new()
  Invoker.const_set(:COMMANDER, commander)
  commander.start_manager()
end

.uninstall_pow(selected_command) ⇒ Object



40
41
42
# File 'lib/invoker/runner.rb', line 40

def self.uninstall_pow(selected_command)
  Invoker::Power::Setup.uninstall()
end

.warn_about_terminal_notifierObject



82
83
84
85
86
87
88
89
# File 'lib/invoker/runner.rb', line 82

def self.warn_about_terminal_notifier
  if RUBY_PLATFORM.downcase.include?("darwin")
    command_path = `which terminal-notifier`
    if !command_path || command_path.empty?
      Invoker::Logger.puts("You can enable OSX notification for processes by installing terminal-notifier gem".color(:red))
    end
  end
end