Skip to content

Commit

Permalink
Maintenance mode doesn't load A/R, so you can't rely on models being …
Browse files Browse the repository at this point in the history
…there. Extract patterns into their own module. close #355.
  • Loading branch information
cmeiklejohn committed Sep 24, 2011
1 parent b7ff386 commit 3f9f018
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
6 changes: 1 addition & 5 deletions app/models/rubygem.rb
@@ -1,9 +1,5 @@
class Rubygem < ActiveRecord::Base class Rubygem < ActiveRecord::Base
SPECIAL_CHARACTERS = ".-_" include Patterns
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/


has_many :owners, :through => :ownerships, :source => :user has_many :owners, :through => :ownerships, :source => :user
has_many :ownerships, :dependent => :destroy has_many :ownerships, :dependent => :destroy
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Expand Up @@ -26,6 +26,8 @@ class Application < Rails::Application
config.middleware.use "Hostess" config.middleware.use "Hostess"
config.middleware.insert_after "Hostess", "Redirector" if $rubygems_config[:redirector] config.middleware.insert_after "Hostess", "Redirector" if $rubygems_config[:redirector]


config.autoload_paths += %W(#{config.root}/lib)

unless Rails.env.maintenance? unless Rails.env.maintenance?
config.action_mailer.default_url_options = { :host => HOST } config.action_mailer.default_url_options = { :host => HOST }
config.action_mailer.delivery_method = $rubygems_config[:delivery_method] config.action_mailer.delivery_method = $rubygems_config[:delivery_method]
Expand Down
3 changes: 3 additions & 0 deletions config/environments/maintenance.rb
@@ -1,4 +1,6 @@
Gemcutter::Application.configure do Gemcutter::Application.configure do
config.active_support.deprecation = :notify

config.middleware.use ::Rack::Static, config.middleware.use ::Rack::Static,
:urls => ["/index.html", :urls => ["/index.html",
"/favicon.ico", "/favicon.ico",
Expand All @@ -7,6 +9,7 @@
:root => "public/maintenance" :root => "public/maintenance"
config.middleware.use ::Rack::Maintenance, config.middleware.use ::Rack::Maintenance,
:file => File.join('public', 'maintenance', 'index.html') :file => File.join('public', 'maintenance', 'index.html')

config.plugins = [] config.plugins = []
end end


Expand Down
12 changes: 6 additions & 6 deletions config/routes.rb
Expand Up @@ -11,7 +11,7 @@
get :top, :on => :collection get :top, :on => :collection
get :all, :on => :collection get :all, :on => :collection
end 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: # In Rails 3.1, the following line can be replaced with:
# resources :downloads, :only => :show, :format => true # resources :downloads, :only => :show, :format => true
get 'downloads/:id.:format', :to => 'downloads#show', :as => 'download' get 'downloads/:id.:format', :to => 'downloads#show', :as => 'download'
Expand All @@ -34,14 +34,14 @@


resources :dependencies, :only => :index 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 collection do
delete :yank delete :yank
put :unyank put :unyank
get :latest get :latest
get :just_updated get :just_updated
end end
constraints :rubygem_id => Rubygem::ROUTE_PATTERN do constraints :rubygem_id => Patterns::ROUTE_PATTERN do
resource :owners, :only => [:show, :create, :destroy] resource :owners, :only => [:show, :create, :destroy]
end end
end end
Expand Down Expand Up @@ -86,17 +86,17 @@
resources :stats, :only => :index resources :stats, :only => :index


resources :rubygems, :only => :index, :path => 'gems' do 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] resource :subscription, :only => [:create, :destroy]
resources :versions, :only => :index resources :versions, :only => :index
resource :stats, :only => :show resource :stats, :only => :show
end end
end end


constraints :id => Rubygem::ROUTE_PATTERN do constraints :id => Patterns::ROUTE_PATTERN do
resources :rubygems, :path => 'gems', :only => [:show, :edit, :update] 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 resources :versions, :only => :show do
resource :stats, :only => :show resource :stats, :only => :show
end end
Expand Down
9 changes: 9 additions & 0 deletions 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

0 comments on commit 3f9f018

Please sign in to comment.