Class: Geminabox::IncomingGem

Inherits:
Object
  • Object
show all
Defined in:
lib/geminabox/incoming_gem.rb

Instance Method Summary collapse

Constructor Details

#initialize(gem_data, root_path = Geminabox.data) ⇒ IncomingGem

Returns a new instance of IncomingGem.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/geminabox/incoming_gem.rb', line 6

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

  digest = Digest::SHA1.new
  @tempfile = Tempfile.new("gem", encoding: "binary", binmode: true)

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

  @tempfile.close
  @sha1 = digest.hexdigest

  @root_path = root_path
end

Instance Method Details

#dest_filenameObject



49
50
51
# File 'lib/geminabox/incoming_gem.rb', line 49

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

#gem_dataObject



25
26
27
# File 'lib/geminabox/incoming_gem.rb', line 25

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

#get_nameObject



43
44
45
46
47
# File 'lib/geminabox/incoming_gem.rb', line 43

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

#hexdigestObject



53
54
55
# File 'lib/geminabox/incoming_gem.rb', line 53

def hexdigest
  @sha1
end

#nameObject



39
40
41
# File 'lib/geminabox/incoming_gem.rb', line 39

def name
  @name ||= get_name
end

#specObject



35
36
37
# File 'lib/geminabox/incoming_gem.rb', line 35

def spec
  @spec ||= Gem::Package.new(@tempfile.path).spec
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/geminabox/incoming_gem.rb', line 29

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