diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-07-20 02:32:23 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-07-20 02:32:37 -0300 |
commit | a8a3a8cc691facad4ba7487a7b66362b498720c9 (patch) | |
tree | edd761712a1f6e01fa6c8801fd670402ef5d1c57 /railties/lib | |
parent | f980dee24eb500e2a8a6e25b2fd13dbe2ce5b62d (diff) | |
parent | e5a6f7ee9e951dbe0e4e9ea2c0743b4dfb135c57 (diff) | |
download | rails-a8a3a8cc691facad4ba7487a7b66362b498720c9.tar.gz rails-a8a3a8cc691facad4ba7487a7b66362b498720c9.tar.bz2 rails-a8a3a8cc691facad4ba7487a7b66362b498720c9.zip |
Merge pull request #25438 from prathamesh-sonpatki/rm-session-store-initializer
Setup default session store internally, no longer through an initializer
Diffstat (limited to 'railties/lib')
4 files changed, 25 insertions, 15 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8e3f01edd7..7d0c3daa23 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -34,8 +34,6 @@ module Rails @public_file_server.index_name = "index" @force_ssl = false @ssl_options = {} - @session_store = :cookie_store - @session_options = {} @time_zone = "UTC" @beginning_of_week = :monday @log_level = nil @@ -165,29 +163,37 @@ module Rails self.generators.colorize_logging = val end - def session_store(*args) - if args.empty? - case @session_store - when :disabled - nil - when :active_record_store + def session_store(new_session_store = nil, **options) + if new_session_store + if new_session_store == :active_record_store begin ActionDispatch::Session::ActiveRecordStore rescue NameError raise "`ActiveRecord::SessionStore` is extracted out of Rails into a gem. " \ "Please add `activerecord-session_store` to your Gemfile to use it." end + end + + @session_store = new_session_store + @session_options = options || {} + else + case @session_store + when :disabled + nil + when :active_record_store + ActionDispatch::Session::ActiveRecordStore when Symbol ActionDispatch::Session.const_get(@session_store.to_s.camelize) else @session_store end - else - @session_store = args.shift - @session_options = args.shift || {} end end + def session_store? #:nodoc: + @session_store + end + def annotations SourceAnnotationExtractor::Annotation end diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index daf3a24b16..64de10a5c7 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -33,6 +33,14 @@ module Rails end end + # Setup default session store if not already set in config/application.rb + initializer :setup_default_session_store, before: :build_middleware_stack do |app| + unless app.config.session_store? + app_name = app.class.name ? app.railtie_name.chomp('_application') : '' + app.config.session_store :cookie_store, key: "_#{app_name}_session" + end + end + initializer :build_middleware_stack do build_middleware_stack end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 2879be5fa2..0390457cdb 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -337,7 +337,6 @@ module Rails def delete_non_api_initializers_if_api_option if options[:api] - remove_file 'config/initializers/session_store.rb' remove_file 'config/initializers/cookies_serializer.rb' end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt deleted file mode 100644 index 2bb9b82c61..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ /dev/null @@ -1,3 +0,0 @@ -# Be sure to restart your server when you modify this file. - -Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %> |