0
class Project < ActiveRecord::Base
0
has_many :comments, :dependent => :destroy
0
has_many :repositories, :order => "repositories.mainline desc, repositories.created_at asc",
0
- has_one :mainline_repository, :conditions => ["mainline = ?", true],
0
+ has_one :mainline_repository, :conditions => ["mainline = ?", true],
0
:class_name => "Repository"
0
has_many :repository_clones, :conditions => ["mainline = ?", false],
0
:class_name => "Repository"
0
- is_indexed :fields => ["title", "description", "slug"],
0
+ is_indexed :fields => ["title", "description", "slug"],
0
- { :class_name => 'Tag',
0
+ { :class_name => 'Tag',
0
- :association_sql => "LEFT OUTER JOIN taggings ON taggings.taggable_id = projects.id " +
0
+ :association_sql => "LEFT OUTER JOIN taggings ON taggings.taggable_id = projects.id " +
0
"AND taggings.taggable_type = 'Project' LEFT OUTER JOIN tags ON taggings.tag_id = tags.id"
0
@@ -23,26 +23,26 @@ class Project < ActiveRecord::Base
0
URL_FORMAT_RE = /^(http|https|nntp):\/\//.freeze
0
validates_presence_of :title, :user_id, :slug
0
validates_uniqueness_of :slug, :case_sensitive => false
0
- validates_format_of :slug, :with => /^[a-z0-9_\-]+$/i,
0
+ validates_format_of :slug, :with => /^[a-z0-9_\-]+$/i,
0
:message => "must match something in the range of [a-z0-9_\-]+"
0
- validates_format_of :home_url, :with => URL_FORMAT_RE,
0
+ validates_format_of :home_url, :with => URL_FORMAT_RE,
0
:if => proc{|record| !record.home_url.blank? },
0
:message => "Must begin with http(s)"
0
validates_format_of :mailinglist_url, :with => URL_FORMAT_RE,
0
:if => proc{|record| !record.mailinglist_url.blank? },
0
:message => "Must begin with http(s)"
0
- validates_format_of :bugtracker_url, :with => URL_FORMAT_RE,
0
+ validates_format_of :bugtracker_url, :with => URL_FORMAT_RE,
0
:if => proc{|record| !record.bugtracker_url.blank? },
0
:message => "Must begin with http(s)"
0
before_validation :downcase_slug
0
after_create :create_mainline_repository
0
'Academic Free License v3.0',
0
@@ -68,47 +68,59 @@ class Project < ActiveRecord::Base
0
'Other/Proprietary License',
0
def self.find_by_slug!(slug, opts = {})
0
find_by_slug(slug, opts) || raise(ActiveRecord::RecordNotFound)
0
def self.per_page() 20 end
0
def self.top_tags(limit = 10)
0
tag_counts(:limit => limit, :order => "count desc")
0
def can_be_deleted_by?(candidate)
0
(candidate == user) && (repositories.size == 1)
0
def tag_list=(tag_list)
0
tag_list.gsub!(",", "")
0
+ self[:home_url] = clean_url(url)
0
+ def mailinglist_url=(url)
0
+ self[:mailinglist_url] = clean_url(url)
0
+ def bugtracker_url=(url)
0
+ self[:bugtracker_url] = clean_url(url)
0
def stripped_description
0
description.gsub(/<\/?[^>]*>/, "")
0
# sanitizer = HTML::WhiteListSanitizer.new
0
# sanitizer.sanitize(description, :tags => %w(str), :attributes => %w(class))
0
info = Proc.new { |options|
0
builder = options[:builder]
0
builder.owner user.login
0
- builder.repositories :type => "array" do
0
+ builder.repositories :type => "array" do
0
repositories.each { |repo|
0
@@ -120,14 +132,22 @@ class Project < ActiveRecord::Base
0
super({:procs => [info]}.merge(opts))
0
def create_mainline_repository
0
self.repositories.create!(:user => self.user, :name => "mainline")
0
+ # Try our best to guess the url
0
+ url = "http://#{url}" if URI.parse(url).class == URI::Generic
Comments
No one has commented yet.