Class: Jets::Booter
- Inherits:
-
Object
- Object
- Jets::Booter
- Defined in:
- lib/jets/booter.rb
Class Method Summary collapse
-
.app_initializers ⇒ Object
All Turbines.
- .boot! ⇒ Object
-
.build_middleware_stack ⇒ Object
Builds and memoize stack so it only gets built on bootup.
- .check_config_ru! ⇒ Object
-
.confirm_jets_project! ⇒ Object
Cannot call this for the jets new.
- .load_internal_turbines ⇒ Object
- .message ⇒ Object
-
.run_turbines(name) ⇒ Object
run_turbines(:initializers) run_turbines(:after_initializers).
-
.setup_db ⇒ Object
Only connects connect to database for ActiveRecord and when config/database.yml exists.
-
.turbine_initializers ⇒ Object
All Turbines.
Class Method Details
.app_initializers ⇒ Object
All Turbines
54 55 56 57 58 |
# File 'lib/jets/booter.rb', line 54 def app_initializers Dir.glob("#{Jets.root}/config/initializers/**/*").each do |path| load path end end |
.boot! ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jets/booter.rb', line 6 def boot! return if @booted confirm_jets_project! Jets::Bundle.require Jets.application.setup! Jets::Dotenv.load! # needs Jets.config.project_name when using ssm in dotenv files # Turbines are loaded after setup_auto_load_paths in Jets.application.setup! Some Turbine options are defined # in the project so setup must happen before internal Turbines are loaded. load_internal_turbines run_turbines(:initializers) # Load configs after Turbine initializers so Turbines can defined some config options and they are available in # user's project environment configs. Jets.application.configs! app_initializers run_turbines(:after_initializers) Jets.application.finish! # Eager load project code. Rather have user find out early than later on AWS Lambda. Jets::Autoloaders.main.eager_load setup_db # TODO: Figure out how to build middleware during Jets.boot without breaking jets new and webpacker:install # build_middleware_stack @booted = true end |
.build_middleware_stack ⇒ Object
Builds and memoize stack so it only gets built on bootup
72 73 74 |
# File 'lib/jets/booter.rb', line 72 def build_middleware_stack Jets.application.build_stack end |
.check_config_ru! ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/jets/booter.rb', line 109 def check_config_ru! config_ru = File.read("#{Jets.root}/config.ru") unless config_ru.include?("Jets.boot") puts 'The config.ru file is missing Jets.boot. Please add Jets.boot after require "jets"'.color(:red) puts "This was changed as made in Jets v1.1.0." puts "To have Jets update the config.fu file for you, you can run:\n\n" puts " jets upgrade" exit 1 end end |
.confirm_jets_project! ⇒ Object
Cannot call this for the jets new
98 99 100 101 102 103 |
# File 'lib/jets/booter.rb', line 98 def confirm_jets_project! unless File.exist?("#{Jets.root}/config/application.rb") puts "It does not look like you are running this command within a jets project. Please confirm that you are in a jets project and try again.".color(:red) exit 1 end end |
.load_internal_turbines ⇒ Object
37 38 39 40 41 |
# File 'lib/jets/booter.rb', line 37 def load_internal_turbines Dir.glob("#{__dir__}/internal/turbines/**/*.rb").each do |path| Jets::Autoloaders.once.preload(path) end end |
.message ⇒ Object
105 106 107 |
# File 'lib/jets/booter.rb', line 105 def "Jets booting up in #{Jets.env.color(:green)} mode!" end |
.run_turbines(name) ⇒ Object
run_turbines(:initializers) run_turbines(:after_initializers)
62 63 64 65 66 67 68 69 |
# File 'lib/jets/booter.rb', line 62 def run_turbines(name) Jets::Turbine.subclasses.each do |subclass| hooks = subclass.send(name) || [] hooks.each do |label, block| block.call(Jets.application) end end end |
.setup_db ⇒ Object
Only connects connect to database for ActiveRecord and when config/database.yml exists. Dynomite handles connecting to the clients lazily.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jets/booter.rb', line 79 def setup_db return unless File.exist?("#{Jets.root}/config/database.yml") db_configs = Jets.application.config.database # DatabaseTasks.database_configuration for db:create db:migrate tasks # Documented in DatabaseTasks that this is the right way to set it when # using ActiveRecord rake tasks outside of Rails. ActiveRecord::Tasks::DatabaseTasks.database_configuration = db_configs current_config = db_configs[Jets.env] if current_config.blank? abort("ERROR: config/database.yml exists but no environment section configured for #{Jets.env}") end # Using ActiveRecord rake tasks outside of Rails, so we need to set up the # db connection ourselves ActiveRecord::Base.establish_connection(current_config) end |
.turbine_initializers ⇒ Object
All Turbines
44 45 46 47 48 49 50 51 |
# File 'lib/jets/booter.rb', line 44 def turbine_initializers Jets::Turbine.subclasses.each do |subclass| initializers = subclass.initializers || [] initializers.each do |label, block| block.call(Jets.application) end end end |