Permalink
Browse files

Maintenance mode doesn't load A/R, so you can't rely on models being …

…there. Extract patterns into their own module. close #355.
  • Loading branch information...
1 parent b7ff386 commit 3f9f018668f8938c2a0b54a0b9717672ac360b64 @cmeiklejohn cmeiklejohn committed Sep 24, 2011
Showing with 21 additions and 11 deletions.
  1. +1 −5 app/models/rubygem.rb
  2. +2 −0 config/application.rb
  3. +3 −0 config/environments/maintenance.rb
  4. +6 −6 config/routes.rb
  5. +9 −0 lib/patterns.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
@@ -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]
@@ -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
View
@@ -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
View
@@ -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

0 comments on commit 3f9f018

Please sign in to comment.