Class: Devkitkat::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/devkitkat/service.rb

Constant Summary collapse

ScriptError =
Class.new(StandardError)
DIVISIONS =
%w[src script data cache log example dockerfile].freeze
SERVICE_PROPERTIES =
%w[repo host port]
SCRIPT_TEMPLATE =
<<-EOS
#!/bin/bash
set -e

# TODO: Define scripts
EOS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config, command) ⇒ Service

Returns a new instance of Service.



23
24
25
# File 'lib/devkitkat/service.rb', line 23

def initialize(name, config, command)
  @name, @config, @command = name, config, command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/devkitkat/service.rb', line 7

def command
  @command
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/devkitkat/service.rb', line 7

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/devkitkat/service.rb', line 7

def name
  @name
end

Instance Method Details

#container_nameObject



59
60
61
# File 'lib/devkitkat/service.rb', line 59

def container_name
  "#{config.application}-#{name}"
end

#execute!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/devkitkat/service.rb', line 27

def execute!
  executor.prepare

  inject_global_variables
  inject_public_variables
  inject_private_variables
  setup_logger

  FileUtils.rm_f(log_path)
  FileUtils.mkdir_p(log_dir)

  method = script.tr('-', '_')

  if File.exist?(script_path)
    executor.write(%Q{echo "This script is a custom script provided by you."})
    executor.write(script_path)
  elsif respond_to?(method, true)
    executor.write(%Q{echo "This script is a predefined script provided by devkitkat."})
    send(method)
  end

  executor.commit.tap do |result|
    raise ScriptError, process_error_message($?) unless result
  end
ensure
  executor.cleanup
end

#log_pathObject



55
56
57
# File 'lib/devkitkat/service.rb', line 55

def log_path
  File.join(log_dir, "#{script}.log")
end

#service_dirObject



79
80
81
# File 'lib/devkitkat/service.rb', line 79

def service_dir
  File.join(kit_root, 'services', name)
end

#shared_script_dirObject



83
84
85
# File 'lib/devkitkat/service.rb', line 83

def shared_script_dir
  File.join(script_dir, 'shared')
end