Class: InspecPlugins::Iggy::FileHelper
- Inherits:
-
Object
- Object
- InspecPlugins::Iggy::FileHelper
- Defined in:
- lib/inspec-iggy/file_helper.rb
Class Method Summary collapse
- .fetch(url) ⇒ Object
-
.parse_json(file) ⇒ Object
boilerplate JSON parsing.
Class Method Details
.fetch(url) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/inspec-iggy/file_helper.rb', line 26 def self.fetch(url) # if this is a file, just return it return url if File.exist?(url) begin URI.parse(url).open rescue OpenURI::HTTPError => e STDERR.puts e. STDERR.puts "ERROR: Parsing error from URL #{url}" exit(-1) end end |
.parse_json(file) ⇒ Object
boilerplate JSON parsing
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/inspec-iggy/file_helper.rb', line 10 def self.parse_json(file) Inspec::Log.debug "Iggy::FileHelper.parse_json file = #{file}" lfile = fetch(file) begin unless File.file?(lfile) STDERR.puts "ERROR: #{lfile} is an invalid file, please check your path." exit(-1) end JSON.parse(File.read(lfile)) rescue JSON::ParserError => e STDERR.puts e. STDERR.puts "ERROR: Parsing error in #{lfile}." exit(-1) end end |