Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require_relative 'boot'
require_relative 'rails_initializable_hack'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Rails5NewDemo
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
include Rails::InitializableHack
end
end

To find out what initializers are run when starts a rails server

↪  rails s                                                                                                                                            Wed Jul 26 13:48:12 CST 2017
load rails_initializable_hack
=> Booting Puma
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
-- run_initializers start --
Bootstrap include Initializable
set_load_path[1]
set_load_path[2]
set_load_path[3]
set_load_path[4]
set_load_path[5]
set_autoload_paths[6]
set_autoload_paths[7]
set_autoload_paths[8]
set_autoload_paths[9]
set_autoload_paths[10]
add_routing_paths[11]
add_routing_paths[12]
add_routing_paths[13]
add_routing_paths[14]
add_routing_paths[15]
add_locales[16]
add_locales[17]
add_locales[18]
add_locales[19]
add_locales[20]
add_view_paths[21]
add_view_paths[22]
add_view_paths[23]
add_view_paths[24]
add_view_paths[25]
load_environment_config[26]
load_environment_config[27]
load_environment_config[28]
load_environment_config[29]
load_environment_config[30]
load_environment_hook[31]
load_active_support[32]
set_eager_load[33]
initialize_logger[34]
initialize_cache[35]
initialize_dependency_mechanism[36]
bootstrap_hook[37]
set_secrets_root[38]
active_support.deprecation_behavior[39]
active_support.initialize_time_zone[40]
active_support.initialize_beginning_of_week[41]
active_support.set_configs[42]
action_dispatch.configure[43]
active_model.secure_password[44]
action_controller.assets_config[45]
action_controller.set_helpers_path[46]
action_controller.parameters_config[47]
action_controller.set_configs[48]
action_controller.compile_config_methods[49]
active_record.initialize_timezone[50]
active_record.logger[51]
active_record.migration_error[52]
active_record.check_schema_cache_dump[53]
active_record.warn_on_records_fetched_greater_than[54]
active_record.set_configs[55]
active_record.initialize_database[56]
active_record.log_runtime[57]
active_record.set_reloader_hooks[58]
active_record.set_executor_hooks[59]
active_record.add_watchable_files[60]
global_id[61]
active_job.logger[62]
active_job.set_configs[63]
active_job.set_reloader_hook[64]
action_mailer.logger[65]
action_mailer.set_configs[66]
action_mailer.compile_config_methods[67]
test_unit.line_filtering[68]
set_default_precompile[69]
quiet_assets[70]
setup_sass[71]
setup_compression[72]
jbuilder[73]
web_console.initialize[74]
web_console.development_only[75]
web_console.insert_middleware[76]
web_console.mount_point[77]
web_console.template_paths[78]
web_console.whitelisted_ips[79]
web_console.whiny_requests[80]
i18n.load_path[81]
prepend_helpers_path[82]
prepend_helpers_path[83]
prepend_helpers_path[84]
prepend_helpers_path[85]
prepend_helpers_path[86]
load_config_initializers[87]
load_config_initializers[88]
load_config_initializers[89]
load_config_initializers[90]
load_config_initializers[91]
engines_blank_point[92]
engines_blank_point[93]
engines_blank_point[94]
engines_blank_point[95]
engines_blank_point[96]
append_assets_path[97]
action_view.embed_authenticity_token_in_remote_forms[98]
action_view.form_with_generates_remote_forms[99]
action_view.logger[100]
action_view.set_configs[101]
action_view.caching[102]
action_view.per_request_digest_cache[103]
action_view.setup_action_pack[104]
action_view.collection_caching[105]
append_assets_path[106]
action_cable.helpers[107]
action_cable.logger[108]
action_cable.set_configs[109]
action_cable.routes[110]
action_cable.set_work_hooks[111]
append_assets_path[112]
override js_template hook[113]
append_assets_path[114]
turbolinks[115]
append_assets_path[116]
add_generator_templates[117]
ensure_autoload_once_paths_as_subset[118]
add_builtin_route[119]
setup_default_session_store[120]
build_middleware_stack[121]
define_main_app_helper[122]
add_to_prepare_blocks[123]
run_prepare_callbacks[124]
eager_load![125]
finisher_hook[126]
configure_executor_for_concurrency[127]
set_routes_reloader_hook[128]
set_clear_dependencies_hook[129]
disable_dependency_loading[130]
-- run_initializers end --
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.0-p0), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop


# save to config/rails_initializable_hack.rb
module Rails
module InitializableHack
def run_initializers(group = :default, *args)
puts "-- run_initializers start --"
return if instance_variable_defined?(:@ran)
counter = 0
initializers.tsort_each do |initializer|
counter += 1
puts "#{initializer.name}[#{counter}]"
initializer.run(*args) if initializer.belongs_to?(group)
end
@ran = true
puts "-- run_initializers end --"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment