Class: BlueprintAgreement::DrakovService

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprint_agreement/api_services/drakov_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDrakovService

Returns a new instance of DrakovService.



5
6
7
8
9
10
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 5

def initialize
  @port = Config.port
  @allow_headers = Config.allow_headers
  @hostname = Config.hostname
  @root_path = Config.server_path
end

Instance Attribute Details

#allow_headersObject (readonly)

Returns the value of attribute allow_headers.



3
4
5
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 3

def allow_headers
  @allow_headers
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



3
4
5
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 3

def hostname
  @hostname
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 3

def pid
  @pid
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 3

def port
  @port
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



3
4
5
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 3

def root_path
  @root_path
end

Instance Method Details

#hostObject



22
23
24
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 22

def host
  "#{hostname}:#{port}"
end

#installObject



30
31
32
33
34
35
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 30

def install
  print "installing drakov.."
  pid = Process.spawn "npm install -g drakov"
  Process.wait pid
  print "Drakov installed 🍺  "
end

#installed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 26

def installed?
  `which drakov`.length > 0
end

#start(path) ⇒ Object



12
13
14
15
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 12

def start(path)
  @pid = spawn "drakov -f #{root_path}/#{path} -p #{port} #{allow_headers}".strip, options
  Config.active_service = { pid: @pid, path: path }
end

#stopObject



17
18
19
20
# File 'lib/blueprint_agreement/api_services/drakov_service.rb', line 17

def stop
  Process.kill 'TERM', Config.active_service[:pid]
  Config.active_service = nil
end