Module: Postpeek::Metadata::ActionMailerContext
- Defined in:
- lib/postpeek/metadata/action_mailer_context.rb
Constant Summary collapse
- THREAD_KEY_CLASS =
:postpeek_mailer_class- THREAD_KEY_ACTION =
:postpeek_mailer_action
Class Method Summary collapse
- .current_action ⇒ Object
- .current_mailer_class ⇒ Object
-
.install! ⇒ Object
Installs an around_action on ActionMailer::Base.
-
.with(mailer_class, action_name) ⇒ Object
Stores mailer context in Thread.current, yields, clears in ensure.
Class Method Details
.current_action ⇒ Object
25 26 27 |
# File 'lib/postpeek/metadata/action_mailer_context.rb', line 25 def self.current_action Thread.current[THREAD_KEY_ACTION] end |
.current_mailer_class ⇒ Object
21 22 23 |
# File 'lib/postpeek/metadata/action_mailer_context.rb', line 21 def self.current_mailer_class Thread.current[THREAD_KEY_CLASS] end |
.install! ⇒ Object
Installs an around_action on ActionMailer::Base. Idempotent: guarded by @installed class-level flag.
31 32 33 34 35 36 37 38 |
# File 'lib/postpeek/metadata/action_mailer_context.rb', line 31 def self.install! return if @installed @installed = true ActionMailer::Base.around_action do |mailer, action| ActionMailerContext.with(mailer.class.name, mailer.action_name) { action.call } end end |
.with(mailer_class, action_name) ⇒ Object
Stores mailer context in Thread.current, yields, clears in ensure.
12 13 14 15 16 17 18 19 |
# File 'lib/postpeek/metadata/action_mailer_context.rb', line 12 def self.with(mailer_class, action_name) Thread.current[THREAD_KEY_CLASS] = mailer_class Thread.current[THREAD_KEY_ACTION] = action_name yield ensure Thread.current[THREAD_KEY_CLASS] = nil Thread.current[THREAD_KEY_ACTION] = nil end |