Class: Duke::Controller

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/duke/controller.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dirObject (readonly)

Returns the value of attribute dir.



5
6
7
# File 'lib/duke/controller.rb', line 5

def dir
  @dir
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/duke/controller.rb', line 5

def port
  @port
end

#repo_dirObject (readonly)

Returns the value of attribute repo_dir.



5
6
7
# File 'lib/duke/controller.rb', line 5

def repo_dir
  @repo_dir
end

#timeoutObject (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_filesObject



7
8
9
# File 'lib/duke/controller.rb', line 7

def self.pid_files
  Dir["#{Config.pid_dir}/*.pid"]
end

Instance Method Details

#controllerObject



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_portObject



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

#identifierObject



34
35
36
# File 'lib/duke/controller.rb', line 34

def identifier
  "#{repo_dir}.#{port}"
end

#log_fileObject



42
43
44
# File 'lib/duke/controller.rb', line 42

def log_file
  "#{dir}/#{Config.log_dir}/#{identifier}.log"
end

#pid_fileObject



38
39
40
# File 'lib/duke/controller.rb', line 38

def pid_file
  "#{dir}/#{Config.pid_dir}/#{identifier}.pid"
end

#ping_commandObject



46
47
48
# File 'lib/duke/controller.rb', line 46

def ping_command
  lambda { TCPSocket.new(Config.host, port) }
end

#running?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/duke/controller.rb', line 30

def running?
  port.nil? ? false : controller.running?
end