Class: Duke::Controller
- Inherits:
-
Object
- Object
- Duke::Controller
- Extended by:
- Forwardable
- Defined in:
- lib/duke/controller.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#repo_dir ⇒ Object
readonly
Returns the value of attribute repo_dir.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #controller ⇒ Object
- #current_port ⇒ Object
- #identifier ⇒ Object
-
#initialize(repo_dir, port = nil) ⇒ Controller
constructor
A new instance of Controller.
- #log_file ⇒ Object
- #pid_file ⇒ Object
- #ping_command ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize(repo_dir, port = nil) ⇒ Controller
Returns a new instance of Controller.
11 12 13 14 15 16 |
# File 'lib/duke/controller.rb', line 11 def initialize(repo_dir, port=nil) @dir = Dir.pwd @repo_dir = repo_dir @port = port @timeout = 7 end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
5 6 7 |
# File 'lib/duke/controller.rb', line 5 def dir @dir end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/duke/controller.rb', line 5 def port @port end |
#repo_dir ⇒ Object (readonly)
Returns the value of attribute repo_dir.
5 6 7 |
# File 'lib/duke/controller.rb', line 5 def repo_dir @repo_dir end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/duke/controller.rb', line 5 def timeout @timeout end |
Class Method Details
.pid_files ⇒ Object
7 8 9 |
# File 'lib/duke/controller.rb', line 7 def self.pid_files Dir["#{Config.pid_dir}/*.pid"] end |
Instance Method Details
#controller ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/duke/controller.rb', line 50 def controller @controller ||= DaemonController.new({ :identifier => identifier, :start_command => "duke cijoed #{repo_dir} #{port} #{log_file} #{pid_file}", :ping_command => ping_command, :pid_file => pid_file, :log_file => log_file, :log_file_activity_timeout => timeout, :start_timeout => timeout }) end |
#current_port ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/duke/controller.rb', line 22 def current_port repo_dir_regex = /#{repo_dir}\.(\d+)/ Controller.pid_files.each do |pid_file| return $1.to_i if pid_file =~ repo_dir_regex end nil end |
#identifier ⇒ Object
34 35 36 |
# File 'lib/duke/controller.rb', line 34 def identifier "#{repo_dir}.#{port}" end |
#log_file ⇒ Object
42 43 44 |
# File 'lib/duke/controller.rb', line 42 def log_file "#{dir}/#{Config.log_dir}/#{identifier}.log" end |
#pid_file ⇒ Object
38 39 40 |
# File 'lib/duke/controller.rb', line 38 def pid_file "#{dir}/#{Config.pid_dir}/#{identifier}.pid" end |
#ping_command ⇒ Object
46 47 48 |
# File 'lib/duke/controller.rb', line 46 def ping_command lambda { TCPSocket.new(Config.host, port) } end |
#running? ⇒ Boolean
30 31 32 |
# File 'lib/duke/controller.rb', line 30 def running? port.nil? ? false : controller.running? end |