Module: A::NtiMannerKickCourse

Defined in:
lib/a/nti_manner_kick_course.rb,
lib/a/nti_manner_kick_course/railtie.rb,
lib/a/nti_manner_kick_course/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

MONITORED_HOOKS =
%i[
 action_controller action_controller_base action_controller_api action_controller_test_case action_dispatch_response action_dispatch_integration_test
 message_pack active_model active_model_translation active_job active_job_test_case active_record_fixtures
 action_cable_connection action_cable_connection_test_case action_cable action_cable_channel action_cable_channel_test_case
 action_text_encrypted_rich_text action_text_record action_text_rich_text action_text_content active_record active_record_fixture_set
 active_record_sqlite3adapter active_record_mysql2adapter active_record_trilogyadapter active_record_postgresqladapter active_record_encryption
 action_view action_view_test_case action_mailer action_mailer_test_case active_storage_blog active_storage_record active_storage_variant_record
 active_storage_attachment action_mailbox_inbound_email action_mailbox_record action_mailbox action_mailbox_test_case
].freeze
VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.already_checkedObject



63
64
65
# File 'lib/a/nti_manner_kick_course.rb', line 63

def already_checked
  @already_checked = true
end

.already_checked?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/a/nti_manner_kick_course.rb', line 59

def already_checked?
  @already_checked
end

.debug?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/a/nti_manner_kick_course.rb', line 21

def debug?
  ENV["ANTI_MANNER_DEBUG"]
end

.enabled?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/a/nti_manner_kick_course.rb', line 17

def enabled?
  ENV["ANTI_MANNER"]
end

.error_message(framework) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/a/nti_manner_kick_course.rb', line 67

def error_message(framework)
  suspect = caller.find { |c| !A::NtiMannerKickCourse.filtering.match?(c) }
  <<~"MESSAGE"
    ❌During Rails startup, the block inside ActiveSupport.on_load(:#{framework}) was executed.
    There is code that is not being deferred as expected. The suspicious part is here.

    #{suspect}

    If you want to check the entire stack trace, set the ANTI_MANNER_DEBUG environment variable.
  MESSAGE
end

.error_message_with_debug(framework) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/a/nti_manner_kick_course.rb', line 79

def error_message_with_debug(framework)
  <<~"MESSAGE"
    ❌During Rails startup, the block inside ActiveSupport.on_load(:#{framework}) was executed.
    There is code that is not being deferred as expected.

    Currently, debug mode is enabled, so the full stack trace is being displayed.
    To show only the suspicious code line, remove the ANTI_MANNER_DEBUG environment variable and rerun.

    #{caller}
  MESSAGE
end

.filteringObject

TODO: We need to make this list more comprehensive.



55
56
57
# File 'lib/a/nti_manner_kick_course.rb', line 55

def filtering
  %r{<internal:|/bundled_gems.rb|/(a-nti_manner_kick_course|activemodel|activesupport|actionpack|activerecord|bootsnap|bundler|zeitwerk)-([0-9\.]+|[0-9a-z]{12})/}
end

.finish_monitoringObject



50
51
52
# File 'lib/a/nti_manner_kick_course.rb', line 50

def finish_monitoring
  @monitoring = false
end

.monitor_gemObject Also known as: monitor



30
31
32
33
34
35
# File 'lib/a/nti_manner_kick_course.rb', line 30

def monitor_gem
  start_monitoring
  add_hooks
  yield
  wrapup!
end

.monitor_rails_startupObject



25
26
27
28
# File 'lib/a/nti_manner_kick_course.rb', line 25

def monitor_rails_startup
  start_monitoring
  add_hooks
end

.monitoring?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/a/nti_manner_kick_course.rb', line 46

def monitoring?
  @monitoring
end

.wrapup!Object



39
40
41
42
43
44
# File 'lib/a/nti_manner_kick_course.rb', line 39

def wrapup!
  A::NtiMannerKickCourse.finish_monitoring

  puts "✅Congratulations! No code was found that fails to defer execution!"
  exit
end