Class: Kontena::Cli::Apps::YAML::Reader

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/kontena/cli/apps/yaml/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

included, #longest_string_in_array, #safe_dig, #time_ago, which

Constructor Details

#initialize(file, skip_validation = false) ⇒ Reader

Returns a new instance of Reader.



13
14
15
16
17
18
19
20
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 13

def initialize(file, skip_validation = false)
  @file = file
  @errors = []
  @notifications = []
  @skip_validation = skip_validation
  load_yaml
  validate unless skip_validation?
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 11

def errors
  @errors
end

#fileObject (readonly)

Returns the value of attribute file.



11
12
13
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 11

def file
  @file
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



11
12
13
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 11

def notifications
  @notifications
end

#yamlObject (readonly)

Returns the value of attribute yaml.



11
12
13
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 11

def yaml
  @yaml
end

Instance Method Details

#execute(service_name = nil) ⇒ Hash

Parameters:

  • service_name (String) (defaults to: nil)

Returns:

  • (Hash)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 25

def execute(service_name = nil)
  result = {}
  Dir.chdir(File.dirname(File.expand_path(file))) do
    result[:version] = yaml['version'] || '1'
    result[:name] = yaml['name']
    result[:errors] = errors
    result[:notifications] = notifications
    result[:services] = errors.count == 0 ? parse_services(service_name) : {}
  end
  result
end

#stack_nameObject



37
38
39
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 37

def stack_name
  yaml['name'] if v2?
end

#v2?true|false

Returns:

  • (true|false)


43
44
45
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 43

def v2?
  yaml['version'].to_s == '2'
end