Skip to content

Commit 8de305c

Browse files
committed
Added dependencies to db and view
1 parent 1613452 commit 8de305c

File tree

11 files changed

+74
-7
lines changed

11 files changed

+74
-7
lines changed

app/helpers/codes_helper.rb

+12
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ def author_links(authors)
2828
link_to(h(author.name), author.permalink)
2929
end.to_sentence
3030
end
31+
32+
def dependency_link_for(gem)
33+
"<a href=\"/#{gem.downcase}\">#{h(gem)}</a>"
34+
end
35+
36+
def dependency_links_for(code)
37+
links = []
38+
(code.dependencies || []).each do |d|
39+
links << dependency_link_for(d.gem)
40+
end
41+
links
42+
end
3143
end

app/models/code.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Code < ActiveRecord::Base
44
has_many :comments, :dependent => :destroy, :order => 'created_at desc'
55
has_many :working_comments, :class_name => 'Comment', :conditions => { :works_for_me => true }
66
has_many :failure_comments, :class_name => 'Comment', :conditions => { :works_for_me => false }
7+
has_many :dependencies
78

89
named_scope :popular, :order => 'comments_count desc'
910
named_scope :unpopular, :order => 'comments_count asc'

app/models/dependency.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Dependency < ActiveRecord::Base
2+
belongs_to :code
3+
end

app/views/codes/show.html.erb

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
<dd><%= author_links(@code.authors) %></dd>
88
<dt>Summary</dt>
99
<dd><%= @code.description_or_summary %></dd>
10+
<% if @code.dependencies and @code.dependencies.size > 0 %>
11+
<dt>Dependencies</dt>
12+
<dd><%= dependency_links_for(@code).join(", ") %></dd>
13+
<% end %>
14+
1015
<% unless @code.c_extension.nil? %>
1116
<dt class="notes">Notes</dt>
1217
<%
@@ -16,7 +21,7 @@ end
1621
if @code.c_extension == true %>
1722
<dd><span class="fails stronger normalcase"><%= @code.name.capitalize %> appears to contain C EXTENSIONS, which are not supported by JRuby.</span></dd>
1823
<% elsif @code.c_extension == false %>
19-
<dd><span class="works stronger normalcase">Good news! <%= @code.name.capitalize %> does not appear to contain C extensions.</span></dd>
24+
<dd><span class="works stronger normalcase">Good news! <%= @code.name.capitalize %> does not appear to contain C extensions.</span></dd>
2025
<% end %>
2126
</dl>
2227

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CreateDependencies < ActiveRecord::Migration
2+
def self.up
3+
create_table :dependencies do |t|
4+
t.integer :code_id, :null => false
5+
t.string :gem, :null => false
6+
end
7+
end
8+
9+
def self.down
10+
drop_table :dependencies
11+
end
12+
end

db/schema.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# It's strongly recommended to check this file into your version control system.
1111

12-
ActiveRecord::Schema.define(:version => 20090527235046) do
12+
ActiveRecord::Schema.define(:version => 20090528020846) do
1313

1414
create_table "authors", :force => true do |t|
1515
t.string "name"
@@ -69,6 +69,11 @@
6969
add_index "comments", ["code_id"], :name => "index_comments_on_code_id"
7070
add_index "comments", ["created_at"], :name => "index_comments_on_created_at"
7171

72+
create_table "dependencies", :force => true do |t|
73+
t.integer "code_id", :null => false
74+
t.string "gem", :null => false
75+
end
76+
7277
create_table "jruby_versions", :force => true do |t|
7378
t.string "version"
7479
end

lib/gem_property.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
class GemProperty
2-
UNSUPPORTED_DEPENDENCIES = %w{ rubyinline eventmachine }
2+
UNSUPPORTED_DEPENDENCIES = %w{ rubyinline }
33

44
def self.set(code)
55
raise(ArgumentError, "Must provide an instance of Code") unless code.is_a?(Code)
66
g = GemProperty.new(code.slug_name)
77
p = g.properties
88
code.c_extension = p[:contains_c_extension]
9+
10+
(p[:dependencies] || []).each do |d|
11+
code.dependencies << Dependency.new(:gem=>d)
12+
end
13+
914
code
1015
end
1116

@@ -27,7 +32,8 @@ def properties
2732
extract_gem
2833

2934
output = {
30-
:contains_c_extension => contains_c_extension?
35+
:contains_c_extension => contains_c_extension?,
36+
:dependencies => dependencies
3137
}
3238
end
3339

@@ -48,6 +54,7 @@ def clean_up(path)
4854

4955
def download_gem
5056
output = `gem fetch #{@gem}`
57+
5158
if output.match(/^Downloaded /)
5259
@file = output.split(" ")[1]
5360
return @file
@@ -76,4 +83,11 @@ def contains_c_extension?
7683
false
7784
end
7885

86+
def dependencies
87+
output = []
88+
gem_specs.dependencies.each do |d|
89+
output << d.name
90+
end
91+
output
92+
end
7993
end

public/stylesheets/styles.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ dt {
299299
}
300300

301301
dt.notes {
302-
padding-bottom: 7px;
302+
padding-bottom: 2px;
303303
}
304304

305305
dd {

test/fixtures/dependencies.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2+
3+
# one:
4+
# column: value
5+
#
6+
# two:
7+
# column: value

test/unit/dependency_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'test_helper'
2+
3+
class DependencyTest < ActiveSupport::TestCase
4+
# Replace this with your real tests.
5+
test "the truth" do
6+
assert true
7+
end
8+
end

test/unit/gem_property_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
class GemPropertyTest < Test::Unit::TestCase
44
def test_with_real_gems
5-
gems = [ [ "eventmachine", {:contains_c_extension=>true} ],
6-
[ "tzinfo", {:contains_c_extension=>false} ] ]
5+
gems = [ [ "thin", { :contains_c_extension=>true, :dependencies => %w{ rack eventmachine daemons} } ],
6+
[ "tzinfo", { :contains_c_extension=>false, :dependencies => [] } ] ]
77

88
gems.each do |gem|
99
gem_name = gem[0]

0 commit comments

Comments
 (0)