Class: Adhearsion::CLI::AhnCommand

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(action, *args) (protected)

Raises:



152
153
154
155
# File 'lib/adhearsion/cli_commands.rb', line 152

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

Class Method Details

+ (Boolean) exit_on_failure?

Returns:

  • (Boolean)


32
33
34
# File 'lib/adhearsion/cli_commands.rb', line 32

def self.exit_on_failure?
  true
end

Instance Method Details

- (Object) create(path)



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

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

- (Object) daemon(path = nil)



64
65
66
# File 'lib/adhearsion/cli_commands.rb', line 64

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

- (Object) generate(generator_name = nil, *args)



43
44
45
46
47
48
49
# File 'lib/adhearsion/cli_commands.rb', line 43

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

- (Object) restart(path = nil)



105
106
107
108
109
110
111
112
113
# File 'lib/adhearsion/cli_commands.rb', line 105

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

- (Object) start(path = nil)



58
59
60
# File 'lib/adhearsion/cli_commands.rb', line 58

def start(path = nil)
  start_app path, :console
end

- (Object) stop(path = nil)

Raises:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/adhearsion/cli_commands.rb', line 70

def stop(path = nil)
  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

- (Object) version



52
53
54
55
# File 'lib/adhearsion/cli_commands.rb', line 52

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