Class: Gitlab::Lint::Client::YamlFile
- Inherits:
-
Object
- Object
- Gitlab::Lint::Client::YamlFile
- Defined in:
- lib/gitlab/lint/client/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) ⇒ YamlFile
constructor
A new instance of YamlFile.
- #validate! ⇒ Object
Constructor Details
#initialize(file) ⇒ YamlFile
Returns a new instance of YamlFile.
11 12 13 14 |
# File 'lib/gitlab/lint/client/yml.rb', line 11 def initialize(file) @file = file validate! end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
9 10 11 |
# File 'lib/gitlab/lint/client/yml.rb', line 9 def file @file end |
Instance Method Details
#get_content ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/gitlab/lint/client/yml.rb', line 23 def get_content begin return YAML.load_file(@file) rescue Psych::SyntaxError => error puts "Failed to parse the YAML File: #{error.}" end end |
#get_json_content ⇒ Object
31 32 33 34 |
# File 'lib/gitlab/lint/client/yml.rb', line 31 def get_json_content content = JSON.generate(get_content()) return json_ok?(content) ? content : nil end |
#validate! ⇒ Object
16 17 18 19 20 21 |
# File 'lib/gitlab/lint/client/yml.rb', line 16 def validate! raise NameError unless @file raise ArgumentError unless @file.chars.last(4).join == ".yml" or @file.chars.last(5).join == ".yaml" raise IOError unless ::File.exist?(@file) raise RuntimeError unless ::File.readable?(@file) end |