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

Version Path
rails_app_generator-0.2.41 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.40 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.39 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.38 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.37 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.36 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.35 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.34 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.33 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.32 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.31 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.30 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.29 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.28 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.27 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.26 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.25 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.24 lib/rails_app_generator/gem_query.rb
rails_app_generator-0.2.23 lib/rails_app_generator/gem_query.rb