Class: Litbuild::ServiceDir

Inherits:
Object
  • Object
show all
Defined in:
lib/litbuild/service_dir.rb

Overview

Service definition directories are a bit complicated. This is just a helper class that knows how to deal with them.

Instance Method Summary collapse

Constructor Details

#initialize(svcdef) ⇒ ServiceDir

Returns a new instance of ServiceDir.



7
8
9
# File 'lib/litbuild/service_dir.rb', line 7

def initialize(svcdef)
  @svcdef = svcdef
end

Instance Method Details

#bundleObject



15
16
17
# File 'lib/litbuild/service_dir.rb', line 15

def bundle
  @svcdef['bundle']&.first
end

#dependenciesObject



35
36
37
# File 'lib/litbuild/service_dir.rb', line 35

def dependencies
  @svcdef['dependencies'] || []
end

#envObject



49
50
51
52
53
54
55
56
57
# File 'lib/litbuild/service_dir.rb', line 49

def env
  return [] unless @svcdef.key?('env')

  flattened = {}
  @svcdef['env'].first.each do |variable, value|
    flattened[variable] = value.first
  end
  flattened
end

#multiline_filesObject



39
40
41
42
43
44
45
46
47
# File 'lib/litbuild/service_dir.rb', line 39

def multiline_files
  file_contents = {}
  %w[up down run].each do |fn|
    next unless @svcdef.key?(fn)

    file_contents[fn] = @svcdef[fn]
  end
  file_contents
end

#nameObject



11
12
13
# File 'lib/litbuild/service_dir.rb', line 11

def name
  @svcdef['name'].first
end

#oneline_filesObject



27
28
29
30
31
32
33
# File 'lib/litbuild/service_dir.rb', line 27

def oneline_files
  file_contents = { 'type' => type }
  %w[down-signal notification-fd].each do |fn|
    file_contents[fn] = @svcdef[fn].first if @svcdef.key?(fn)
  end
  file_contents
end

#typeObject

Raises:



19
20
21
22
23
24
25
# File 'lib/litbuild/service_dir.rb', line 19

def type
  return @svcdef['type'].first if @svcdef.key?('type')
  return 'longrun' if @svcdef.key?('run')
  return 'oneshot' if @svcdef.key?('up')

  raise(InvalidDirective, "servicedir #{name} must specify type")
end