Class: Kontena::Cli::Apps::YAML::Reader
- Inherits:
-
Object
- Object
- Kontena::Cli::Apps::YAML::Reader
- Includes:
- Util
- Defined in:
- lib/kontena/cli/apps/yaml/reader.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#yaml ⇒ Object
readonly
Returns the value of attribute yaml.
Instance Method Summary collapse
- #execute(service_name = nil) ⇒ Hash
-
#initialize(file, skip_validation = false) ⇒ Reader
constructor
A new instance of Reader.
- #stack_name ⇒ Object
- #v2? ⇒ true|false
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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 11 def errors @errors end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 11 def file @file end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
11 12 13 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 11 def notifications @notifications end |
#yaml ⇒ Object (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
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.(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_name ⇒ Object
37 38 39 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 37 def stack_name yaml['name'] if v2? end |
#v2? ⇒ true|false
43 44 45 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 43 def v2? yaml['version'].to_s == '2' end |