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
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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
10 11 12 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 10 def errors @errors end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
10 11 12 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 10 def file @file end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
10 11 12 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 10 def notifications @notifications end |
#yaml ⇒ Object (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
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.(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
36 37 38 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 36 def stack_name yaml['name'] if v2? end |
#v2? ⇒ true|false
42 43 44 |
# File 'lib/kontena/cli/apps/yaml/reader.rb', line 42 def v2? yaml['version'].to_s == '2' end |