Upgrade to Pro — share decks privately, control downloads, hide ads and more …

dive to Ruby on Rails module autoloading

teitei_tk
October 29, 2018

dive to Ruby on Rails module autoloading

teitei_tk

October 29, 2018
Tweet

More Decks by teitei_tk

Other Decks in Programming

Transcript

  1. ಛఆͷσΟϨΫτϦ is teitei.tk >> !(master) ~/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading $ bin/rails r 'puts

    ActiveSupport::Dependencies.autoload_paths' Running via Spring preloader in process 39294 /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/assets /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/channels /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/controllers /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/controllers/concerns /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/helpers /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/jobs /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/mailers /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/models /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/app/models/concerns /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/vendor/bundle/ruby/2.5.0/gems/ activestorage-5.2.1/app/assets /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/vendor/bundle/ruby/2.5.0/gems/ activestorage-5.2.1/app/controllers /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/vendor/bundle/ruby/2.5.0/gems/ activestorage-5.2.1/app/controllers/concerns /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/vendor/bundle/ruby/2.5.0/gems/ activestorage-5.2.1/app/javascript /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/vendor/bundle/ruby/2.5.0/gems/ activestorage-5.2.1/app/jobs /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/vendor/bundle/ruby/2.5.0/gems/ activestorage-5.2.1/app/models /Users/teitei.tk/.golang/src/github.com/teitei-tk/dive-to-rails-autoloading/test/mailers/previews
  2. Rails::Engine.eager_load! # Eager load the application by loading all ruby

    # files inside eager_load paths. def eager_load! config.eager_load_paths.each do |load_path| matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/ Dir.glob("#{load_path}/**/*.rb").sort.each do |file| require_dependency file.sub(matcher, '\1') end end end
  3. ͳ͔ͥ • ౴͑͸Rails::Engine.initializer set_load_path ʹ͋Γ·͢ɻ # Add configured load paths

    to Ruby's load path, and remove duplicate entries. initializer :set_load_path, before: :bootstrap_hook do _all_load_paths.reverse_each do |path| $LOAD_PATH.unshift(path) if File.directory?(path) end $LOAD_PATH.uniq! end