Class: Devkitkat::Service
- Inherits:
-
Object
- Object
- Devkitkat::Service
- 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
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #container_name ⇒ Object
- #execute ⇒ Object
- #execute! ⇒ Object
-
#initialize(name, config, command) ⇒ Service
constructor
A new instance of Service.
- #log_path ⇒ Object
- #service_dir ⇒ Object
- #shared_script_dir ⇒ Object
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/devkitkat/service.rb', line 7 def command @command end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/devkitkat/service.rb', line 7 def config @config end |
#name ⇒ Object (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_name ⇒ Object
69 70 71 |
# File 'lib/devkitkat/service.rb', line 69 def container_name "#{config.application}-#{name}" end |
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/devkitkat/service.rb', line 27 def execute execute! true rescue ScriptError => e puts "Failure: #{e}".colorize(:red) false end |
#execute! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/devkitkat/service.rb', line 37 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, ($?) unless result end ensure executor.cleanup end |
#log_path ⇒ Object
65 66 67 |
# File 'lib/devkitkat/service.rb', line 65 def log_path File.join(log_dir, "#{script}.log") end |
#service_dir ⇒ Object
89 90 91 |
# File 'lib/devkitkat/service.rb', line 89 def service_dir File.join(kit_root, 'services', name) end |
#shared_script_dir ⇒ Object
93 94 95 |
# File 'lib/devkitkat/service.rb', line 93 def shared_script_dir File.join(script_dir, 'shared') end |