class Falkor::Gem

Attributes

created_at[R]
info[R]
name[R]
project_uri[R]
version[R]

Public Class Methods

find(query, version = nil) click to toggle source
# File lib/falkor/gem.rb, line 21
def find(query, version = nil)
  gem_info =
    if version.nil?
      Gems.info(query)
    else
      rubygems_v2_info(query, version)
    end

  new(**gem_info.transform_keys(&:to_sym))
end
new(**attrs) click to toggle source
# File lib/falkor/gem.rb, line 44
def initialize(**attrs)
  @name        = attrs[:name]
  @info        = attrs[:info]
  @created_at  = attrs[:created_at] && Time.parse(attrs[:created_at])
  @project_uri = attrs[:homepage_uri]
  @version     = ::Gem::Version.new(attrs[:version])
end

Private Class Methods

rubygems_v2_info(gem_name, version) click to toggle source
# File lib/falkor/gem.rb, line 34
def rubygems_v2_info(gem_name, version)
  response = Gems::Client.new.get(
    "/api/v2/rubygems/#{gem_name}/versions/#{version}.json"
  )
  JSON.parse(response)
rescue JSON::ParserError
  {}
end

Public Instance Methods

other_versions() click to toggle source
# File lib/falkor/gem.rb, line 52
def other_versions
  @other_versions ||= Gems.versions(name).map do |payload|
    next if payload["number"] == version

    self.class.new(
      name: name,
      info: payload["summary"],
      version: payload["number"],
      created_at: payload["created_at"]
    )
  end.compact
end

Private Instance Methods

extract(file_path) { |:extracting, progress| ... } click to toggle source
# File lib/falkor/gem.rb, line 85
def extract(file_path)
  Falkor::Extract::TarGz.new(
    Falkor::Extract::Gem.new(file_path).extract
  ).extract do |progress|
    yield :extracting, progress
  end
end
file_name() click to toggle source
# File lib/falkor/gem.rb, line 73
def file_name
  "#{name}-#{version}.gem"
end
url() click to toggle source
# File lib/falkor/gem.rb, line 77
def url
  "https://rubygems.org/gems/#{file_name}"
end
yard_filepath() click to toggle source
# File lib/falkor/gem.rb, line 81
def yard_filepath
  File.join(Dir.pwd, "tmp", File.basename(file_name, ".gem") + ".falkor")
end