Class: Rubee::Autoload
- Inherits:
-
Object
- Object
- Rubee::Autoload
- Defined in:
- lib/rubee/autoload.rb
Constant Summary collapse
- BLACKLIST =
['rubee.rb', 'test_helper.rb', 'puma.rb']
Class Method Summary collapse
- .call(black_list = [], **options) ⇒ Object
- .load_envs!(prefix = , root_directory) ⇒ Object
- .load_inits(root_directory, black_list) ⇒ Object
- .load_middlewares(root_directory, black_list) ⇒ Object
- .load_support(root_directory, black_list) ⇒ Object
- .load_whitelisted(white_list_dirs) ⇒ Object
- .priority_order_require(root_directory, black_list) ⇒ Object
Class Method Details
.call(black_list = [], **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rubee/autoload.rb', line 5 def call(black_list = [], **) load_whitelisted([:white_list_dirs]) && return if [:white_list_dirs] # Autoload all rbs root_directory = File.join(Rubee::ROOT_PATH, '/lib') load_middlewares(root_directory, black_list) priority_order_require(root_directory, black_list) load_inits(root_directory, black_list) # Ensure sequel object is connected Rubee::SequelObject.reconnect! Dir.glob(File.join(Rubee::APP_ROOT, '**', '*.rb')) .sort_by { |file| file.include?('/models/') ? 0 : 1 } .each do |file| base_name = File.basename(file) unless base_name.end_with?('_test.rb') || (black_list + BLACKLIST).include?(base_name) require_relative file end end end |
.load_envs!(prefix = , root_directory) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rubee/autoload.rb', line 63 def load_envs!(prefix = ENV['RACK_ENV'], root_directory) env_file_name = "#{root_directory}/.#{prefix}.env" File.foreach(env_file_name) do |line| line = line.strip next if line.empty? || line.start_with?('#') key, value = line.split('=', 2) ENV[key] = value end rescue => _ end |
.load_inits(root_directory, black_list) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubee/autoload.rb', line 46 def load_inits(root_directory, black_list) # rubee inits Dir[File.join(root_directory, 'inits/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end # app inits Dir[File.join(Rubee::APP_ROOT, 'inits/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end end |
.load_middlewares(root_directory, black_list) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubee/autoload.rb', line 27 def load_middlewares(root_directory, black_list) # rubee middlewares Dir[File.join(Rubee::ROOT_PATH, '/lib', '/rubee/internal_middlewares/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end # project middlewares Dir[File.join(root_directory, 'middlewares/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end end |
.load_support(root_directory, black_list) ⇒ Object
57 58 59 60 61 |
# File 'lib/rubee/autoload.rb', line 57 def load_support(root_directory, black_list) Dir[File.join(Rubee::ROOT_PATH, '/lib', '/rubee/support/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end end |
.load_whitelisted(white_list_dirs) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rubee/autoload.rb', line 38 def load_whitelisted(white_list_dirs) white_list_dirs.each do |dir| Dir[File.join(Rubee::ROOT_PATH, '/lib', "#{dir}/**", '*.rb')].each do |file| require_relative file end end end |
.priority_order_require(root_directory, black_list) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rubee/autoload.rb', line 74 def priority_order_require(root_directory, black_list) # rubee pub sub Dir[File.join(root_directory, 'rubee/pubsub/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end # rubee websocket Dir[File.join(root_directory, 'rubee/websocket/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end # rubee async Dir[File.join(root_directory, 'rubee/async/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end load_support(root_directory, black_list) load_envs!(ENV['RACK_ENV'], root_directory) # app config and routes unless black_list.include?('base_configuration.rb') require_relative File.join(Rubee::APP_ROOT, Rubee::LIB, 'config/base_configuration') end require_relative File.join(Rubee::APP_ROOT, Rubee::LIB, 'config/routes') unless black_list.include?('routes.rb') # rubee extensions Dir[File.join(root_directory, 'rubee/extensions/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end # rubee controllers Dir[File.join(root_directory, 'rubee/controllers/middlewares/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end Dir[File.join(root_directory, 'rubee/controllers/extensions/**', '*.rb')].each do |file| require_relative file unless black_list.include?("#{file}.rb") end unless black_list.include?('base_controller.rb') require_relative File.join(root_directory, 'rubee/controllers/base_controller') end # rubee models unless black_list.include?('assoc_array.rb') require_relative File.join(root_directory, 'rubee/models/assoc_array') end unless black_list.include?('database_objectable.rb') require_relative File.join(root_directory, 'rubee/models/database_objectable') end return if black_list.include?('sequel_object.rb') require_relative File.join(root_directory, 'rubee/models/sequel_object') return if black_list.include?('db_tools.rb') require_relative File.join(root_directory, 'rubee/models/db_tools') Dir[File.join(root_directory, 'rubee/cli/**', '*.rb')].each do |file| require_relative file end end |