lib/sequel_rails/railtie.rb in sequel-rails-1.0.0 vs lib/sequel_rails/railtie.rb in sequel-rails-1.0.1

- old
+ new

@@ -36,16 +36,20 @@ config.sequel = ::SequelRails::Configuration.new rake_tasks do |app| load_tasks_config = app.config.sequel.load_database_tasks + SequelRails::TASK_NAMESPACE = case load_tasks_config when Symbol, String then load_tasks_config.to_sym else :db end + load 'sequel_rails/railties/database.rake' if load_tasks_config + + check_skip_connect_conditions(app) end initializer 'sequel.load_hooks' do ::ActiveSupport.run_load_hooks(:sequel, ::Sequel::Model) end @@ -66,11 +70,11 @@ initializer 'sequel.log_runtime' do |_app| setup_controller_runtime end initializer 'sequel.connect' do |app| - ::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect] + ::SequelRails.setup(::Rails.env) if database_connection_required?(app) end initializer 'sequel.spring' do |_app| if defined?(::Spring::Application) class ::Spring::Application # rubocop:disable Style/ClassAndModuleChildren @@ -102,8 +106,20 @@ end def setup_controller_runtime require 'sequel_rails/railties/controller_runtime' ActionController::Base.send :include, SequelRails::Railties::ControllerRuntime + end + + def check_skip_connect_conditions(app) + app.config.sequel[:skip_connect] ||= database_create_command? + end + + def database_connection_required?(app) + !app.config.sequel[:skip_connect] + end + + def database_create_command? + ["db:create", "db:create:all"].any? { |c| ARGV.include?(c) } end end end