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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/duke/controller.rb', line 46

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



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

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

#log_fileObject



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

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

#pid_fileObject



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

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

#ping_commandObject



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

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