3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails5のinitializerの読み込み順序を検証

Posted at

結論

通常 mode 検証

読み込まれたファイル名をログに吐き出す一文を足すfishスクリプトを用意。まだ実行しない。

add-log.fish
#!/usr/bin/env fish

# usage:
# /PATH/TO/RAILS_APP_HOME/add-log.fish

for file in config/initializers/*.rb
  echo "`echo #{__FILE__} >> $PWD/log/seq.log`" >> $file
end
for file in config/initializers/*/*.rb
  echo "`echo #{__FILE__} >> $PWD/log/seq.log`" >> $file
end

apiモードでrails newを実行し、前後関係を調べるためのダミーファイルを作成。

bundle exec rails new . -T --no-rc
bundle exec rails g scaffold user
bundle exec rails db:migrate
touch config/initializers/aa.rb
touch config/initializers/zz.rb
touch config/initializers/1z.rb
mkdir config/initializers/0
touch config/initializers/0/zzzzzzz.rb

chmod u+x add-log.fish
./add-log.fish

bundle exec rails s
log/seq.log
# 説明に不要な文字列は削除済み

config/initializers/0/zzzzzzz.rb
config/initializers/1z.rb
config/initializers/aa.rb

config/initializers/application_controller_renderer.rb
config/initializers/assets.rb
config/initializers/backtrace_silencers.rb
config/initializers/cookies_serializer.rb
config/initializers/filter_parameter_logging.rb
config/initializers/inflections.rb
config/initializers/mime_types.rb
config/initializers/new_framework_defaults.rb
config/initializers/session_store.rb
config/initializers/wrap_parameters.rb

config/initializers/zz.rb

api mode 検証

読み込まれたファイル名をログに吐き出す一文を足すfishスクリプトを用意。まだ実行しない。

add-log.fish
#!/usr/bin/env fish

# usage:
# /PATH/TO/RAILS_APP_HOME/add-log.fish

for file in config/initializers/*.rb
  echo "`echo #{__FILE__} >> $PWD/log/seq.log`" >> $file
end
for file in config/initializers/*/*.rb
  echo "`echo #{__FILE__} >> $PWD/log/seq.log`" >> $file
end

apiモードでrails newを実行し、前後関係を調べるためのダミーファイルを作成。

bundle exec rails new . --api -T --no-rc
bundle exec rails g scaffold user
bundle exec rails db:migrate
touch config/initializers/aa.rb
touch config/initializers/zz.rb
touch config/initializers/1z.rb
mkdir config/initializers/0
touch config/initializers/0/zzzzzzz.rb

chmod u+x add-log.fish
./add-log.fish

bundle exec rails s
log/seq.log
# 説明に不要な文字列は削除済み

config/initializers/0/zzzzzzz.rb
config/initializers/1z.rb
config/initializers/aa.rb

config/initializers/application_controller_renderer.rb
config/initializers/backtrace_silencers.rb
config/initializers/cors.rb
config/initializers/filter_parameter_logging.rb
config/initializers/inflections.rb
config/initializers/mime_types.rb
config/initializers/new_framework_defaults.rb
config/initializers/wrap_parameters.rb

config/initializers/zz.rb
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?