lib/tls_map/utils.rb in tls-map-1.3.0 vs lib/tls_map/utils.rb in tls-map-1.3.1
- old
+ new
@@ -1,24 +1,29 @@
# frozen_string_literal: true
# Ruby internal
require 'net/http'
require 'tempfile'
+require 'json'
# TLS map module
module TLSmap
# Generic utilities
module Utils
- def tmpfile(name, url)
+ def self.tmpfile(name, url)
tmp = Tempfile.new(name)
tmp.write(Net::HTTP.get(URI(url)))
tmp.close
tmp
end
- end
- # TLS mapping
- class App
- include Utils
- protected :tmpfile
+ # bring JSON.load_file before ruby 3.0.0
+ # https://ruby-doc.org/stdlib-3.0.0/libdoc/json/rdoc/JSON.html#method-i-load_file
+ def self.json_load_file(filespec, opts = {})
+ if RUBY_VERSION < '3.0.0'
+ JSON.parse(File.read(filespec), opts)
+ else
+ JSON.load_file(filespec, opts)
+ end
+ end
end
end