geminabox 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geminabox might be problematic. Click here for more details.

data/lib/geminabox.rb CHANGED
@@ -1,7 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
1
4
  require "digest/md5"
2
5
  require "builder"
3
6
  require 'sinatra/base'
4
- require 'rubygems'
5
7
  require 'rubygems/builder'
6
8
  require "rubygems/indexer"
7
9
 
@@ -45,6 +47,11 @@ class Geminabox < Sinatra::Base
45
47
  erb :upload
46
48
  end
47
49
 
50
+ get '/reindex' do
51
+ reindex
52
+ redirect "/"
53
+ end
54
+
48
55
  delete '/gems/*.gem' do
49
56
  File.delete file_path if File.exists? file_path
50
57
  reindex
@@ -113,15 +120,14 @@ HTML
113
120
  %w(specs prerelease_specs).inject(GemVersionCollection.new){|gems, specs_file_type|
114
121
  specs_file_path = File.join(options.data, "#{specs_file_type}.#{Gem.marshal_version}.gz")
115
122
  if File.exists?(specs_file_path)
116
- gems + Marshal.load(Gem.gunzip(Gem.read_binary(specs_file_path)))
117
- else
118
- gems
123
+ gems |= Geminabox::GemVersionCollection.new(Marshal.load(Gem.gunzip(Gem.read_binary(specs_file_path))))
119
124
  end
125
+ gems
120
126
  }
121
127
  end
122
128
 
123
129
  def index_gems(gems)
124
- Set.new(gems.map{|name, _| name[0..0]})
130
+ Set.new(gems.map{|gem| gem.name[0..0]})
125
131
  end
126
132
 
127
133
  helpers do
@@ -0,0 +1,27 @@
1
+ class Geminabox::GemVersion
2
+ attr_accessor :name, :number, :platform
3
+
4
+ def initialize(name, number, platform)
5
+ @name = name
6
+ @number = number
7
+ @platform = platform
8
+ end
9
+
10
+ def ruby?
11
+ !!(platform =~ /ruby/i)
12
+ end
13
+
14
+ def <=>(other)
15
+ sort = other.name <=> name
16
+ sort = other.number <=> number if sort.zero?
17
+ sort = (other.ruby? && !ruby?) ? 1 : -1 if sort.zero? && ruby? != other.ruby?
18
+ sort = other.platform <=> platform if sort.zero?
19
+
20
+ sort
21
+ end
22
+
23
+ def gemfile_name
24
+ included_platform = ruby? ? nil : platform
25
+ [name, number, included_platform].compact.join('-')
26
+ end
27
+ end
@@ -1,26 +1,49 @@
1
+ require 'geminabox/gem_version'
2
+
1
3
  class Geminabox::GemVersionCollection
2
4
  include Enumerable
3
5
 
4
- def initialize(initial_gems = [])
5
- @gems = Hash.new{|h,k| h[k] = [] }
6
- initial_gems.each{|g| self << g }
6
+ attr_reader :gems
7
+
8
+ def initialize(initial_gems=[])
9
+ @gems = []
10
+ initial_gems.each { |gemdef| self << gemdef }
7
11
  end
8
12
 
9
- def <<(gemdef)
10
- name,version,_ = gemdef
11
- return self if name.nil?
12
- @gems[name] += [version].flatten
13
- @gems[name].sort!
14
- self
13
+ def <<(version_or_def)
14
+ version = if version_or_def.is_a?(Geminabox::GemVersion)
15
+ version_or_def
16
+ else
17
+ Geminabox::GemVersion.new(*version_or_def)
18
+ end
19
+
20
+ @gems << version
21
+ @gems.sort!
15
22
  end
16
23
 
17
- def + other
18
- other.inject(self.class.new(self)){|new_set, gemdef|
19
- new_set << gemdef
20
- }
24
+ def |(other)
25
+ self.class.new(self.gems | other.gems)
21
26
  end
22
27
 
23
28
  def each(&block)
24
- @gems.sort_by{|name, versions| name }.each(&block)
29
+ @gems.each(&block)
30
+ end
31
+
32
+ def by_name
33
+ grouped = @gems.inject(hash_of_collections) do |grouped, gem|
34
+ grouped[gem.name] << gem
35
+ grouped
36
+ end
37
+
38
+ if block_given?
39
+ grouped.each(&Proc.new)
40
+ else
41
+ grouped
42
+ end
43
+ end
44
+
45
+ private
46
+ def hash_of_collections
47
+ Hash.new { |h,k| h[k] = self.class.new }
25
48
  end
26
49
  end
data/public/master.css CHANGED
@@ -9,6 +9,12 @@ body {
9
9
  margin: 0;
10
10
  }
11
11
 
12
+ small {
13
+ color: #999;
14
+ font-size: 60%;
15
+ }
16
+
17
+
12
18
  a {
13
19
  text-decoration: none;
14
20
  color: #00a;
@@ -110,3 +116,19 @@ ul.gemlist li .delete-form:hover button {
110
116
  margin-top: 1.0em;
111
117
  color: #aaa;
112
118
  }
119
+
120
+
121
+ .gem-version form p {
122
+ margin: 0;
123
+ padding: 1px 0;
124
+ border: 0;
125
+ font-weight: normal;
126
+ font-style: normal;
127
+ font-size: 100%;
128
+ line-height: 1;
129
+ font-family: inherit;
130
+ }
131
+
132
+ .gem-version small.platform {
133
+ padding: 0 0 0 15px;
134
+ }
data/views/index.erb CHANGED
@@ -5,12 +5,17 @@
5
5
 
6
6
  <ul class="gemlist">
7
7
 
8
- <% @gems.each do |name, versions| %>
9
- <li <%= %{id="jump_#{name[0..0]}"} if @index_gems.delete(name[0..0]) %>>
10
- <h2><%= name %> (<%= versions.size == 1 ? versions.first : "#{versions.first} - #{versions.last}" %>)</h2>
8
+ <% @gems.by_name do |name, versions| %>
9
+ <li <%= %{id="jump_#{name[0..0]}"} if @index_gems.delete(name[0..0]) %> class="gem-version">
10
+ <h2><%= name %> (<%= versions.count == 1 ? versions.first.number : "#{versions.first.number} - #{versions.first.number}" %>)</h2>
11
11
  <% versions.each do |version| %>
12
- <form class="delete-form" method="post" action="/gems/<%= name %>-<%= version %>.gem">
13
- <code>gem install <%= name %> <%= "--prerelease" if version.to_s.match(/[a-z]/i) %> -v "<%= version %>"</code>
12
+ <form class="delete-form" method="post" action="/gems/<%= version.gemfile_name %>.gem">
13
+ <p>
14
+ <code>gem install <%= version.name %> <%= "--prerelease" if version.number.to_s.match(/[a-z]/i) %> -v "<%= version.number %>"</code>
15
+ <% unless version.platform =~ /^ruby/i %>
16
+ <small class="platform"><%= version.platform %></small>
17
+ <% end %>
18
+ </p>
14
19
  <input type="hidden" name="_method" value="DELETE" />
15
20
  <button type="submit">delete</button>
16
21
  </form>
@@ -18,7 +23,7 @@
18
23
 
19
24
  <div class="details">
20
25
  <p>
21
- <% if spec = spec_for(name, versions.last) %>
26
+ <% if spec = spec_for(name, versions.first.number) %>
22
27
  <%= spec.description %>
23
28
  <br/>
24
29
  <span class="author">– <%= spec.authors.map do |author|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geminabox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Lea
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-27 00:00:00 +01:00
19
- default_executable:
18
+ date: 2011-12-06 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: sinatra
@@ -56,6 +55,7 @@ extra_rdoc_files:
56
55
  - README.markdown
57
56
  files:
58
57
  - README.markdown
58
+ - lib/geminabox/gem_version.rb
59
59
  - lib/geminabox/gem_version_collection.rb
60
60
  - lib/geminabox.rb
61
61
  - lib/hostess.rb
@@ -69,7 +69,6 @@ files:
69
69
  - views/index.erb
70
70
  - views/layout.erb
71
71
  - views/upload.erb
72
- has_rdoc: true
73
72
  homepage: http://tomlea.co.uk/p/gem-in-a-box
74
73
  licenses: []
75
74
 
@@ -100,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
99
  requirements: []
101
100
 
102
101
  rubyforge_project:
103
- rubygems_version: 1.5.0
102
+ rubygems_version: 1.8.10
104
103
  signing_key:
105
104
  specification_version: 3
106
105
  summary: Really simple rubygem hosting