module Invoker

Constants

VERSION

Attributes

commander[RW]
config[RW]
daemonize[RW]
daemonize?[RW]
dns_cache[RW]
tail_watchers[RW]

Public Class Methods

can_run_balancer?(throw_warning = true) click to toggle source
# File lib/invoker.rb, line 72
def can_run_balancer?(throw_warning = true)
  return true if File.exist?(Invoker::Power::Config.config_file)

  if throw_warning
    Invoker::Logger.puts("Invoker has detected setup has not been run. Domain feature will not work without running setup command.".color(:red))
  end
  false
end
check_and_notify_with_terminal_notifier(message) click to toggle source
# File lib/invoker.rb, line 114
def check_and_notify_with_terminal_notifier(message)
  command_path = `which terminal-notifier`
  if command_path && !command_path.empty?
    system("terminal-notifier -message '#{message}' -title Invoker")
  end
end
close_socket(socket) click to toggle source
# File lib/invoker.rb, line 62
def close_socket(socket)
  socket.close
rescue StandardError => error
  Invoker::Logger.puts "Error removing socket #{error}"
end
daemon() click to toggle source
# File lib/invoker.rb, line 68
def daemon
  @daemon ||= Invoker::Daemon.new
end
darwin?() click to toggle source
# File lib/invoker.rb, line 43
def darwin?
  ruby_platform.downcase.include?("darwin")
end
default_tld() click to toggle source
# File lib/invoker.rb, line 148
def default_tld
  'dev'
end
home() click to toggle source

On some platforms `Dir.home` or `ENV` does not return home directory of user. this is especially true, after effective and real user id of process has been changed.

@return [String] home directory of the user

# File lib/invoker.rb, line 140
def home
  if File.writable?(Dir.home)
    Dir.home
  else
    Etc.getpwuid(Process.uid).dir
  end
end
linux?() click to toggle source
# File lib/invoker.rb, line 47
def linux?
  ruby_platform.downcase.include?("linux")
end
load_invoker_config(file, port) click to toggle source
# File lib/invoker.rb, line 55
def load_invoker_config(file, port)
  @config = Invoker::Parsers::Config.new(file, port)
  @dns_cache = Invoker::DNSCache.new(@invoker_config)
  @tail_watchers = Invoker::CLI::TailWatcher.new
  @commander = Invoker::Commander.new
end
migrate_old_config(old_config, config_location) click to toggle source
# File lib/invoker.rb, line 128
def migrate_old_config(old_config, config_location)
  new_config = File.join(config_location, 'config')
  File.open(new_config, 'w') do |file|
    file.write(old_config)
  end
end
notify_user(message) click to toggle source
# File lib/invoker.rb, line 106
def notify_user(message)
  if Invoker.darwin?
    run_without_bundler { check_and_notify_with_terminal_notifier(message) }
  elsif Invoker.linux?
    notify_with_libnotify(message)
  end
end
notify_with_libnotify(message) click to toggle source
# File lib/invoker.rb, line 121
def notify_with_libnotify(message)
  begin
    require "libnotify"
    Libnotify.show(body: message, summary: "Invoker", timeout: 2.5)
  rescue LoadError; end
end
ruby_platform() click to toggle source
# File lib/invoker.rb, line 51
def ruby_platform
  RUBY_PLATFORM
end
run_without_bundler() { || ... } click to toggle source
# File lib/invoker.rb, line 96
def run_without_bundler
  if defined?(Bundler)
    Bundler.with_clean_env do
      yield
    end
  else
    yield
  end
end
setup_config_location() click to toggle source
# File lib/invoker.rb, line 81
def setup_config_location
  config_dir = Invoker::Power::Config.config_dir
  return config_dir if Dir.exist?(config_dir)

  if File.exist?(config_dir)
    old_config = File.read(config_dir)
    FileUtils.rm_f(config_dir)
  end

  FileUtils.mkdir(config_dir)

  migrate_old_config(old_config, config_dir) if old_config
  config_dir
end