Sha256: 01dedd30d8e7dbef16f1b8617a1408d92f9836283e6502975d580be75d4f5d2b
Contents?: true
Size: 962 Bytes
Versions: 19
Compression:
Stored size: 962 Bytes
Contents
# frozen_string_literal: true # Retrieve GemInfo from RubyGems.org module RailsAppGenerator # GemQuery queries RubyGems for GemEntry. class GemQuery class << self def get(name) gem_info = query_ruby_gems(name) return gem_info if gem_info return query_ruby_gems(name.gsub('_', '-')) if name.include?('_') return query_ruby_gems(name.gsub('-', '_')) if name.include?('-') abort "Cannot find GEM (#{name}) on RubyGems.org" end private def query_ruby_gems(name) link = "https://rubygems.org/api/v1/gems/#{name.downcase}.json" info = Net::HTTP.get(URI.parse(link)) json = JSON.parse(info) Rails::Generators::AppBase::GemfileEntry.new(json['name'], json['version'], json['description']) rescue SocketError abort 'Internet connection cannot be established to RubyGems.org' rescue JSON::ParserError nil end end end end
Version data entries
19 entries across 19 versions & 1 rubygems