Class: GitLab::CI::Lint::YMLReader
- Inherits:
-
Object
- Object
- GitLab::CI::Lint::YMLReader
- Defined in:
- lib/gitlab/ci/lint/yml.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #get_content ⇒ Object
- #get_json_content ⇒ Object
-
#initialize(file) ⇒ YMLReader
constructor
A new instance of YMLReader.
- #validate! ⇒ Object
Constructor Details
#initialize(file) ⇒ YMLReader
Returns a new instance of YMLReader.
9 10 11 12 |
# File 'lib/gitlab/ci/lint/yml.rb', line 9 def initialize file @file = file validate! end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/gitlab/ci/lint/yml.rb', line 8 def file @file end |
Instance Method Details
#get_content ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/gitlab/ci/lint/yml.rb', line 20 def get_content begin return YAML.load(File.read(@file)) rescue ArgumentError => error puts "Could not parse the YAML File: #{error.}" end end |
#get_json_content ⇒ Object
28 29 30 31 |
# File 'lib/gitlab/ci/lint/yml.rb', line 28 def get_json_content content = JSON.pretty_generate(get_content()) return valid_json?(content) ? content : nil end |
#validate! ⇒ Object
14 15 16 17 18 |
# File 'lib/gitlab/ci/lint/yml.rb', line 14 def validate! unless @file.chars.last(4).join == ".yml" or @file.chars.last(5).join == ".yaml" raise ArgumentError.new("We need a YML File...") end end |