Sha256: 800af07b2d5747f97e58d42bfc7ec8bd2f259c2f671a79850ce1e8b181cff025

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

class Geminabox::IncomingGem
  def initialize(gem_data, root_path = Geminabox.settings.data)
    unless gem_data.respond_to? :read
      raise ArgumentError, "Expected an instance of IO"
    end

    digest = Digest::SHA1.new
    if RbConfig::CONFIG["MAJOR"].to_i <= 1 and RbConfig::CONFIG["MINOR"].to_i <= 8
      @tempfile = Tempfile.new("gem")
    else
      @tempfile = Tempfile.new("gem", :encoding => 'binary')
    end

    while data = gem_data.read(1024**2)
      @tempfile.write data
      digest << data
    end

    @tempfile.close
    @sha1 = digest.hexdigest

    @root_path = root_path
  end

  def gem_data
    File.open(@tempfile.path, "rb")
  end

  def valid?
    spec && spec.name && spec.version
  rescue Gem::Package::Error
    false
  end

  def spec
    @spec ||= extract_spec
  end

  def extract_spec
    if Gem::Package.respond_to? :open
      Gem::Package.open(gem_data, "r", nil) do |pkg|
        return pkg.metadata
      end
    else
      Gem::Package.new(@tempfile.path).spec
    end
  end

  def name
    unless @name
      filename = %W[#{spec.name} #{spec.version}]
      filename.push(spec.platform) if spec.platform && spec.platform != "ruby"
      @name = filename.join("-") + ".gem"
    end
    @name
  end

  def dest_filename
    File.join(@root_path, "gems", name)
  end

  def hexdigest
    @sha1
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
geminabox-0.11.1 lib/geminabox/incoming_gem.rb
geminabox-inflection-0.12.0 lib/geminabox/incoming_gem.rb
geminabox-inflection-0.11.0 lib/geminabox/incoming_gem.rb
geminabox-0.11.0 lib/geminabox/incoming_gem.rb
geminabox-bootstrap-0.10.3 lib/geminabox/incoming_gem.rb