module JWTear::Helpers::Utils
Public Instance Methods
check_dependencies(deps={})
click to toggle source
check dependencies for plugins and throw a gentle error if not installed
@param deps [Hash]
The key is the key is the gem name to be installed, the value is library to be require
@example
deps = {'async-io' => 'async/ip'} check_dependencies(deps)
# File lib/jwtear/helpers/utils.rb, line 37 def check_dependencies(deps={}) return if deps.empty? or deps.nil? missing = [] deps.each do |gem, lib| begin require lib rescue LoadError missing << gem end end ensure unless missing.nil? or missing.empty? print_error "Missing dependencies!" print_warning "Please install as follows:" puts "gem install #{missing.join(' ')}" exit! end end
latest_version()
click to toggle source
Check latest version
# File lib/jwtear/helpers/utils.rb, line 6 def latest_version begin current_version = JWTear::VERSION rubygem_api = JSON.parse open("https://rubygems.org/api/v1/versions/jwtear.json").read remote_version = rubygem_api.first["number"] latest = remote_version.eql?(current_version)? true : false latest ? current_version : remote_version rescue Exception => e print_bad " Couldn't check the latest version, please check internet connectivity." exit! end end
read_key(key)
click to toggle source
read key as a string or from file(eg. pub_key.pem)
# File lib/jwtear/helpers/utils.rb, line 21 def read_key(key) if File.exist?(key.to_s) && File.file?(key.to_s) File.read(File.absolute_path(key)) else key end end