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:



134
135
136
137
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 134

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

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 16

def self.exit_on_failure?
  true
end

Instance Method Details

#create(path) ⇒ Object



22
23
24
25
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 22

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

#daemon(path = nil) ⇒ Object



50
51
52
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 50

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

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



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

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

#restart(path = nil) ⇒ Object



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

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



44
45
46
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 44

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

#stop(path = nil) ⇒ Object

Raises:



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
86
87
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 56

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



37
38
39
40
# File 'lib/adhearsion/cli_commands/ahn_command.rb', line 37

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