Class: Edaemon::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/edaemon/server.rb

Constant Summary collapse

PID_FILE_PATH =
'./edaemon.pid'
LOG_FILE_PATH =
'./edaemon.log'
STARTED =
:started
STOPPED =
:stopped
Error =
Class.new(StandardError)
ApplicationAllreadyRunnedError =
Class.new(Error)
BlockNotSettedError =
Class.new(Error)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block: nil) ⇒ Server



14
15
16
# File 'lib/edaemon/server.rb', line 14

def initialize(block: nil)
  @block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



34
35
36
# File 'lib/edaemon/server.rb', line 34

def block
  @block
end

Instance Method Details

#startObject

TODO: Конфиг лога TODO: Конфиг пид файла



20
21
22
23
24
25
26
27
28
# File 'lib/edaemon/server.rb', line 20

def start
  # TODO: simplecov raise почему не подсвечивается
  raise ApplicationAllreadyRunnedError if status == STARTED
  raise BlockNotSettedError unless block

  pid = fork_block!
  save_pid!(pid: pid)
  pid
end

#statusObject



30
31
32
# File 'lib/edaemon/server.rb', line 30

def status
  pid_runned?(pid: saved_pid) ? STARTED : STOPPED
end