Class: Adhearsion::CLI::AhnCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/adhearsion/cli_commands/ahn_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, *args) ⇒ Object (protected)

Raises:


139
140
141
142
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 139

def method_missing(action, *args)
  help
  raise UnknownCommand, [action, *args] * " "
end

Class Method Details

.exit_on_failure?Boolean


14
15
16
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 14

def self.exit_on_failure?
  true
end

Instance Method Details

#create(path) ⇒ Object


20
21
22
23
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 20

def create(path)
  require 'adhearsion/generators/app/app_generator'
  Generators::AppGenerator.start
end

#daemon(path = nil) ⇒ Object


48
49
50
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 48

def daemon(path = nil)
  start_app path, :daemon, options[:pidfile]
end

#generate(generator_name = nil, *args) ⇒ Object


26
27
28
29
30
31
32
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 26

def generate(generator_name = nil, *args)
  if generator_name
    Generators.invoke generator_name
  else
    help 'generate'
  end
end

#restart(path = nil) ⇒ Object


89
90
91
92
93
94
95
96
97
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 89

def restart(path = nil)
  path = execute_from_app_dir! path
  begin
    invoke :stop
  rescue PIDReadError => e
    puts e.message
  end
  invoke :daemon
end

#start(path = nil) ⇒ Object


42
43
44
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 42

def start(path = nil)
  start_app path, options[:noconsole] ? :simple : :console
end

#stop(path = nil) ⇒ Object

Raises:


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 54

def stop(path = nil)
  path = execute_from_app_dir! path

  pid_file = if options[:pidfile]
    File.exists?(File.expand_path(options[:pidfile])) ?
      options[:pidfile] :
      File.join(path, options[:pidfile])
  else
    path = Dir.pwd
    File.join path, Adhearsion::Initializer::DEFAULT_PID_FILE_NAME
  end
  pid_file = File.expand_path pid_file

  begin
    pid = File.read(pid_file).to_i
  rescue
    raise PIDReadError, pid_file
  end

  raise PIDReadError, pid_file if pid.nil?

  say "Stopping Adhearsion server at #{path} with pid #{pid}"
  waiting_timeout = Time.now + 15
  begin
    ::Process.kill "TERM", pid
    sleep 0.25 while process_exists?(pid) && Time.now < waiting_timeout
    ::Process.kill "KILL", pid
  rescue Errno::ESRCH
  end

  File.delete pid_file if File.exists? pid_file
end

#versionObject


35
36
37
38
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 35

def version
  say "Adhearsion v#{Adhearsion::VERSION}"
  exit 0
end