Class: StimulusReflex::SanityChecker
- Inherits:
-
Object
- Object
- StimulusReflex::SanityChecker
- Defined in:
- lib/stimulus_reflex/utils/sanity_checker.rb
Class Method Summary collapse
Instance Method Summary collapse
- #caching_not_enabled? ⇒ Boolean
- #check_caching_enabled ⇒ Object
- #check_default_url_config ⇒ Object
- #default_url_config_set? ⇒ Boolean
- #initializer_missing? ⇒ Boolean
- #using_null_store? ⇒ Boolean
- #warn_and_exit(text) ⇒ Object
Class Method Details
.check! ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 5 def check! return if ENV["SKIP_SANITY_CHECK"] return if StimulusReflex.config.on_failed_sanity_checks == :ignore return if called_by_installer? return if called_by_generate_config? return if called_by_rake? instance = new instance.check_caching_enabled # instance.check_default_url_config end |
Instance Method Details
#caching_not_enabled? ⇒ Boolean
70 71 72 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 70 def caching_not_enabled? Rails.application.config.action_controller.perform_caching == false end |
#check_caching_enabled ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 34 def check_caching_enabled if caching_not_enabled? warn_and_exit " \u{1F449} StimulusReflex requires caching to be enabled. Caching allows the session to be modified during ActionCable requests.\n\n To enable caching in development, run:\n\n rails dev:cache\n WARN\n end\n\n if using_null_store?\n warn_and_exit <<~WARN\n \u{1F449} StimulusReflex requires caching to be enabled.\n\n Caching allows the session to be modified during ActionCable requests. Your config.cache_store is set to :null_store, so it won't work.\n WARN\n end\nend\n" |
#check_default_url_config ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 54 def check_default_url_config return if StimulusReflex.config.on_missing_default_urls == :ignore if default_url_config_missing? puts " \u{1F449} StimulusReflex strongly suggests that you set default_url_options in your environment files. Otherwise, ActionController \#{\"and ActionMailer \" if defined?(ActionMailer)}will default to example.com when rendering route helpers.\n\n You can set your URL options in config/environments/\#{Rails.env}.rb\n\n config.action_controller.default_url_options = {host: \"localhost\", port: 3000}\n \#{\"config.action_mailer.default_url_options = {host: \\\"localhost\\\", port: 3000}\\n\" if defined?(ActionMailer)}\n Please update every environment with the appropriate URL. Typically, no port is necessary in production.\n\n WARN\n end\nend\n" |
#default_url_config_set? ⇒ Boolean
82 83 84 85 86 87 88 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 82 def default_url_config_set? if defined?(ActionMailer) Rails.application.config.action_controller..blank? || Rails.application.config.action_mailer..blank? else Rails.application.config.action_controller..blank? end end |
#initializer_missing? ⇒ Boolean
78 79 80 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 78 def initializer_missing? File.exist?(Rails.root.join("config", "initializers", "stimulus_reflex.rb")) == false end |
#using_null_store? ⇒ Boolean
74 75 76 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 74 def using_null_store? Rails.application.config.cache_store == :null_store end |
#warn_and_exit(text) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/stimulus_reflex/utils/sanity_checker.rb', line 90 def warn_and_exit(text) puts puts "Heads up! 🔥" puts puts text puts if StimulusReflex.config.on_failed_sanity_checks == :exit puts " To ignore any warnings and start the application anyway, you can set the SKIP_SANITY_CHECK environment variable:\n\n SKIP_SANITY_CHECK=true rails\n\n To do this permanently, add the following directive to the StimulusReflex initializer:\n\n StimulusReflex.configure do |config|\n config.on_failed_sanity_checks = :warn\n end\n\n INFO\n exit false unless Rails.env.test?\n end\nend\n" |