class Gitlab::Lint::Client::YamlFile
Attributes
file[R]
Public Class Methods
new(file)
click to toggle source
# File lib/gitlab/lint/client/yml.rb, line 11 def initialize(file) @file = file validate! end
Public Instance Methods
get_content()
click to toggle source
# 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.message}" end end
get_json_content()
click to toggle source
# 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!()
click to toggle source
# 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
Private Instance Methods
json_ok?(json)
click to toggle source
# File lib/gitlab/lint/client/yml.rb, line 38 def json_ok? json begin JSON.parse(json) return true rescue return false end end