Class: Daemons::Rails::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/daemons/rails/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_path) ⇒ Controller

Returns a new instance of Controller.



6
7
8
9
# File 'lib/daemons/rails/controller.rb', line 6

def initialize(controller_path)
  @path = controller_path
  @app_name = "#{controller_path.basename.to_s[0...-'_ctl'.length]}.rb"
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



4
5
6
# File 'lib/daemons/rails/controller.rb', line 4

def app_name
  @app_name
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/daemons/rails/controller.rb', line 4

def path
  @path
end

Instance Method Details

#run(command, argv = {}) ⇒ Object



11
12
13
14
15
# File 'lib/daemons/rails/controller.rb', line 11

def run(command, argv={})
  arguments = '-- '
  argv.each {|key,value| arguments += "#{key} #{value} "}
  `cd "#{Daemons::Rails.configuration.root}" && "#{path}" #{command} #{arguments unless argv.empty?}`
end

#start(argv = {}) ⇒ Object



17
18
19
# File 'lib/daemons/rails/controller.rb', line 17

def start(argv={})
  run('start',argv)
end

#statusObject



25
26
27
# File 'lib/daemons/rails/controller.rb', line 25

def status
  run('status').to_s.split("\n").last =~ /: running \[pid \d+\]$/ ? :running : :not_exists
end

#stopObject



21
22
23
# File 'lib/daemons/rails/controller.rb', line 21

def stop
  run('stop')
end