Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moving downloads into rubygems, making the homepage work

  • Loading branch information...
commit bf06b91c5e228831ebc26ad892206ae6117239dc 1 parent e68656c
Nick Quaranto qrush authored
5 app/controllers/home_controller.rb
View
@@ -1,7 +1,8 @@
class HomeController < ApplicationController
def index
@count = Rubygem.count
- @created_gems = Rubygem.by_created_at(:desc).limited(5)
- @updated_gems = Rubygem.by_updated_at(:desc).limited(5)
+ @new = Rubygem.by_created_at(:desc).limited(5)
+ @updated = Version.by_created_at(:desc).limited(5)
+ @downloaded = Rubygem.by_downloads(:desc).limited(5)
end
end
3  app/metal/hostess.rb
View
@@ -21,8 +21,7 @@ class Hostess < Sinatra::Default
name = original_name[0..-2].join('-')
version = original_name[-1]
rubygem = Rubygem.find_by_name(name)
- version = rubygem.versions.find_by_number(version)
- version.increment!(:downloads)
+ rubygem.increment!(:downloads)
send_file(current_path)
else
halt 404
14 app/models/rubygem.rb
View
@@ -12,8 +12,6 @@ class Rubygem < ActiveRecord::Base
before_validation :build
after_save :store
- default_scope :order => 'name ASC'
-
def self.pull_spec(data)
Gem::Format.from_file_by_path(data.path).spec
end
@@ -26,6 +24,18 @@ def to_param
name.gsub(/[^\w_-]/, "")
end
+ def current_version
+ versions.first
+ end
+
+ def with_version
+ "#{name} (#{current_version})"
+ end
+
+ def with_downloads
+ "#{name} (#{downloads})"
+ end
+
protected
def build
return unless self.spec
5 app/models/version.rb
View
@@ -1,5 +1,10 @@
class Version < ActiveRecord::Base
+ include Pacecar
belongs_to :rubygem
default_scope :order => 'created_at DESC'
+
+ def to_s
+ number
+ end
end
39 app/views/home/index.html.haml
View
@@ -13,27 +13,18 @@
.count= number_with_delimiter(@count)
.what gems indexed since may 2009
.clear
- .list.grid_4
- %h3 Updated Gems
- %ul
- %li jekyll (0.5.1)
- %li haml (0.1.2)
- %li roodi (1.2.3)
- %li beardo (0.0.1)
- %li jeweler (1.0.42)
- .list.grid_4
- %h3 New Gems
- %ul
- %li awesome (0.0.1)
- %li rstuff (1.0.0)
- %li dbhelper (4.1.8)
- %li acts_as_fu (1.0.0)
- %li RTrickery (0.0.0)
- .list.grid_4
- %h3 Most Downloads
- %ul
- %li rails (12,147)
- %li instantrails (9,234)
- %li rmagick (3,403)
- %li rake (2,302)
- %li net/ssh (2,128)
+.list.grid_4
+ %h3 Updated Gems
+ %ul
+ -@updated.each do |version|
+ %li= link_to "#{version.rubygem} (#{version})", version.rubygem
+.list.grid_4
+ %h3 New Gems
+ %ul
+ -@new.each do |gem|
+ %li= link_to gem.with_version, gem
+.list.grid_4
+ %h3 Most Downloads
+ %ul
+ -@downloaded.each do |gem|
+ %li= link_to gem.with_downloads, gem
2  app/views/rubygems/show.html.haml
View
@@ -16,7 +16,7 @@
%p= @current_version.authors
.block.red
%h3 Downloads
- %p= @current_version.downloads
+ %p= number_with_delimiter(@gem.downloads)
.block.red
%h3 Last Update
%p= @current_version.created_at.to_date.to_formatted_s(:long)
11 db/migrate/20090530145834_move_downloads_to_rubygems.rb
View
@@ -0,0 +1,11 @@
+class MoveDownloadsToRubygems < ActiveRecord::Migration
+ def self.up
+ remove_column :versions, :downloads
+ add_column :rubygems, :downloads, :integer, :default => 0
+ end
+
+ def self.down
+ add_column :versions, :downloads, :integer, :default => 0
+ remove_column :rubygems, :downloads
+ end
+end
4 db/schema.rb
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090527122658) do
+ActiveRecord::Schema.define(:version => 20090530145834) do
create_table "dependencies", :force => true do |t|
t.string "name"
@@ -25,6 +25,7 @@
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "downloads", :default => 0
end
create_table "users", :force => true do |t|
@@ -43,7 +44,6 @@
create_table "versions", :force => true do |t|
t.string "authors"
t.text "description"
- t.integer "downloads", :default => 0
t.string "number"
t.integer "rubygem_id"
t.datetime "created_at"
5 public/stylesheets/application.css
View
@@ -170,6 +170,11 @@ h3 {
padding:0.3em;
}
+.list li a {
+ color: inherit;
+ display: block;
+}
+
.list li:hover {
background:#600000;
cursor: pointer;
5 test/functional/home_controller_test.rb
View
@@ -4,8 +4,9 @@ class HomeControllerTest < ActionController::TestCase
context "on GET to index" do
setup do
mock(Rubygem).count { 1337 }
- mock(Rubygem).by_created_at(:desc).stub!.limited(5)
- mock(Rubygem).by_updated_at(:desc).stub!.limited(5)
+ mock(Rubygem).by_created_at(:desc).stub!.limited(5) { [] }
+ mock(Version).by_created_at(:desc).stub!.limited(5) { [] }
+ mock(Rubygem).by_downloads(:desc).stub!.limited(5) { [] }
get :index
end
should_respond_with :success
12 test/unit/rubygem_test.rb
View
@@ -14,6 +14,18 @@ class RubygemTest < ActiveSupport::TestCase
should "return name for #to_s" do
assert_equal @rubygem.name, @rubygem.to_s
end
+
+ should "return latest version for #current_version" do
+ assert_equal @rubygem.versions.first, @rubygem.current_version
+ end
+
+ should "return name with version for #with_version" do
+ assert_equal "#{@rubygem.name} (#{@rubygem.current_version})", @rubygem.with_version
+ end
+
+ should "return name with downloads for #with_downloads" do
+ assert_equal "#{@rubygem.name} (#{@rubygem.downloads})", @rubygem.with_downloads
+ end
end
should "pull spec out of the given gem" do
10 test/unit/version_test.rb
View
@@ -2,4 +2,14 @@
class VersionTest < ActiveSupport::TestCase
should_belong_to :rubygem
+
+ context "with a version" do
+ setup do
+ @version = Factory(:version)
+ end
+
+ should "give number for #to_s" do
+ assert_equal @version.number, @version.to_s
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.