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

Constructor Details

#initialize(file, skip_validation = false) ⇒ Reader

Returns a new instance of Reader.



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

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.



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

def errors
  @errors
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



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

def notifications
  @notifications
end

#yamlObject (readonly)

Returns the value of attribute yaml.



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

def yaml
  @yaml
end

Instance Method Details

#execute(service_name = nil) ⇒ Hash

Parameters:

  • service_name (String) (defaults to: nil)

Returns:

  • (Hash)


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

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



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

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

#v2?true|false

Returns:

  • (true|false)


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

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