diff --git a/app/models/rubygem.rb b/app/models/rubygem.rb index 1f7d41dc1fc..0f040bf63f9 100644 --- a/app/models/rubygem.rb +++ b/app/models/rubygem.rb @@ -1,9 +1,5 @@ class Rubygem < ActiveRecord::Base - SPECIAL_CHARACTERS = ".-_" - ALLOWED_CHARACTERS = "[A-Za-z0-9#{Regexp.escape(SPECIAL_CHARACTERS)}]+" - ROUTE_PATTERN = /#{ALLOWED_CHARACTERS}/ - LAZY_ROUTE_PATTERN = /#{ALLOWED_CHARACTERS}?/ - NAME_PATTERN = /\A#{ALLOWED_CHARACTERS}\Z/ + include Patterns has_many :owners, :through => :ownerships, :source => :user has_many :ownerships, :dependent => :destroy diff --git a/config/application.rb b/config/application.rb index 718bb42ff8e..b6b253f7366 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,6 +26,8 @@ class Application < Rails::Application config.middleware.use "Hostess" config.middleware.insert_after "Hostess", "Redirector" if $rubygems_config[:redirector] + config.autoload_paths += %W(#{config.root}/lib) + unless Rails.env.maintenance? config.action_mailer.default_url_options = { :host => HOST } config.action_mailer.delivery_method = $rubygems_config[:delivery_method] diff --git a/config/environments/maintenance.rb b/config/environments/maintenance.rb index c8f530db5ef..796f3413e2e 100644 --- a/config/environments/maintenance.rb +++ b/config/environments/maintenance.rb @@ -1,4 +1,6 @@ Gemcutter::Application.configure do + config.active_support.deprecation = :notify + config.middleware.use ::Rack::Static, :urls => ["/index.html", "/favicon.ico", @@ -7,6 +9,7 @@ :root => "public/maintenance" config.middleware.use ::Rack::Maintenance, :file => File.join('public', 'maintenance', 'index.html') + config.plugins = [] end diff --git a/config/routes.rb b/config/routes.rb index 945b7d423b6..834855cbf6f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ get :top, :on => :collection get :all, :on => :collection end - constraints :id => Rubygem::ROUTE_PATTERN, :format => /json|xml|yaml/ do + constraints :id => Patterns::ROUTE_PATTERN, :format => /json|xml|yaml/ do # In Rails 3.1, the following line can be replaced with: # resources :downloads, :only => :show, :format => true get 'downloads/:id.:format', :to => 'downloads#show', :as => 'download' @@ -34,14 +34,14 @@ resources :dependencies, :only => :index - resources :rubygems, :path => 'gems', :only => [:create, :show, :index], :id => Rubygem::LAZY_ROUTE_PATTERN, :format => /json|xml|yaml/ do + resources :rubygems, :path => 'gems', :only => [:create, :show, :index], :id => Patterns::LAZY_ROUTE_PATTERN, :format => /json|xml|yaml/ do collection do delete :yank put :unyank get :latest get :just_updated end - constraints :rubygem_id => Rubygem::ROUTE_PATTERN do + constraints :rubygem_id => Patterns::ROUTE_PATTERN do resource :owners, :only => [:show, :create, :destroy] end end @@ -86,17 +86,17 @@ resources :stats, :only => :index resources :rubygems, :only => :index, :path => 'gems' do - constraints :rubygem_id => Rubygem::ROUTE_PATTERN do + constraints :rubygem_id => Patterns::ROUTE_PATTERN do resource :subscription, :only => [:create, :destroy] resources :versions, :only => :index resource :stats, :only => :show end end - constraints :id => Rubygem::ROUTE_PATTERN do + constraints :id => Patterns::ROUTE_PATTERN do resources :rubygems, :path => 'gems', :only => [:show, :edit, :update] do - constraints :rubygem_id => Rubygem::ROUTE_PATTERN do + constraints :rubygem_id => Patterns::ROUTE_PATTERN do resources :versions, :only => :show do resource :stats, :only => :show end diff --git a/lib/patterns.rb b/lib/patterns.rb new file mode 100644 index 00000000000..d1d228fad3e --- /dev/null +++ b/lib/patterns.rb @@ -0,0 +1,9 @@ +module Patterns + extend ActiveSupport::Concern + + SPECIAL_CHARACTERS = ".-_" + ALLOWED_CHARACTERS = "[A-Za-z0-9#{Regexp.escape(SPECIAL_CHARACTERS)}]+" + ROUTE_PATTERN = /#{ALLOWED_CHARACTERS}/ + LAZY_ROUTE_PATTERN = /#{ALLOWED_CHARACTERS}?/ + NAME_PATTERN = /\A#{ALLOWED_CHARACTERS}\Z/ +end