rails_band 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97783d31ff40a28fa21181d954f365769bfcaf03a08557572363d90399e32347
4
- data.tar.gz: 9e32469800f4a9b9e818e928283278975fd50408f24bee7d0241a7018e86e1f6
3
+ metadata.gz: '0252268a8e05795a32afaf52c744143ad84aa806d8b06fe45ff480572b4e3d12'
4
+ data.tar.gz: ae7ef45e64e0b645afe122d54da499274d5281f4182e7beb831b33ccd118c25a
5
5
  SHA512:
6
- metadata.gz: e63696203569e2126281fa79e7ec42ad4c8a09fdd04597eb41ae73cc1fd98b977776513e4f701304a8eb58a1597cb5940f2f920b3fe683c8df7262bc40adfffe
7
- data.tar.gz: f267534e31f135a5a216eab5e41a0298f4b59c9ba17f4a683fb212bb1d10bf8eb2e024646fae669e16b315399a0e412f814dbd7d432222b60a2e6345b44fa0c5
6
+ metadata.gz: 8d077ace78ac6724596f894854076b6fb9d6863423452e1af2e9fd23be765247827f4e446b310fc2dcb8cdddb6c565453f7b3b7cd90d8b7714d5b634b207510f
7
+ data.tar.gz: be8704ee197bc96fce8ec5f68921cab394d7b96a77500a2e6a267d41cfd2e8a5a9efd310a345a6b5b2967033c4824cd39cb478f8467de83eb02eacfe674f1212
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # rails_band
2
2
 
3
+ <a href="https://github.com/yykamei/rails_band/actions/workflows/ci.yml"><img alt="GitHub Actions workflow status" src="https://github.com/yykamei/rails_band/actions/workflows/ci.yml/badge.svg"></a>
4
+ <a href="https://rubygems.org/gems/rails_band"><img alt="Gem" src="https://img.shields.io/gem/v/rails_band"></a>
5
+
3
6
  Easy-to-use Rails Instrumentation API.
4
7
 
5
8
  ## Installation
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionMailer
5
+ module Event
6
+ # A wrapper for the event that is passed to `deliver.action_mailer`.
7
+ class Deliver < BaseEvent
8
+ def mailer
9
+ @mailer ||= @event.payload.fetch(:mailer)
10
+ end
11
+
12
+ def message_id
13
+ @message_id ||= @event.payload.fetch(:message_id)
14
+ end
15
+
16
+ def subject
17
+ @subject ||= @event.payload.fetch(:subject)
18
+ end
19
+
20
+ def to
21
+ @to ||= @event.payload.fetch(:to)
22
+ end
23
+
24
+ def from
25
+ @from ||= @event.payload.fetch(:from)
26
+ end
27
+
28
+ def bcc
29
+ @bcc ||= @event.payload[:bcc] || []
30
+ end
31
+
32
+ def cc
33
+ @cc ||= @event.payload[:cc] || []
34
+ end
35
+
36
+ def date
37
+ @date ||= @event.payload.fetch(:date)
38
+ end
39
+
40
+ def mail
41
+ @mail ||= @event.payload.fetch(:mail)
42
+ end
43
+
44
+ def perform_deliveries
45
+ @perform_deliveries ||= @event.payload.fetch(:perform_deliveries)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActionMailer
5
+ module Event
6
+ # A wrapper for the event that is passed to `process.action_mailer`.
7
+ class Process < BaseEvent
8
+ def mailer
9
+ @mailer ||= @event.payload.fetch(:mailer)
10
+ end
11
+
12
+ def action
13
+ @action ||= @event.payload.fetch(:action)
14
+ end
15
+
16
+ def args
17
+ @args ||= @event.payload.fetch(:args)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_band/action_mailer/event/deliver'
4
+ require 'rails_band/action_mailer/event/process'
5
+
6
+ module RailsBand
7
+ module ActionMailer
8
+ # The custom LogSubscriber for ActionMailer.
9
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
10
+ mattr_accessor :consumers
11
+
12
+ def deliver(event)
13
+ consumer_of(__method__)&.call(Event::Deliver.new(event))
14
+ end
15
+
16
+ def process(event)
17
+ consumer_of(__method__)&.call(Event::Process.new(event))
18
+ end
19
+
20
+ private
21
+
22
+ def consumer_of(sub_event)
23
+ consumers[:"#{sub_event}.action_mailer"] || consumers[:action_mailer] || consumers[:default]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -24,6 +24,11 @@ module RailsBand
24
24
  require 'active_record/log_subscriber'
25
25
  swap.call(::ActiveRecord::LogSubscriber, RailsBand::ActiveRecord::LogSubscriber, :active_record)
26
26
  end
27
+
28
+ if defined?(::ActionMailer)
29
+ require 'action_mailer/log_subscriber'
30
+ swap.call(::ActionMailer::LogSubscriber, RailsBand::ActionMailer::LogSubscriber, :action_mailer)
31
+ end
27
32
  end
28
33
  end
29
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBand
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/rails_band.rb CHANGED
@@ -19,4 +19,8 @@ module RailsBand
19
19
  module ActiveRecord
20
20
  autoload :LogSubscriber, 'rails_band/active_record/log_subscriber'
21
21
  end
22
+
23
+ module ActionMailer
24
+ autoload :LogSubscriber, 'rails_band/action_mailer/log_subscriber'
25
+ end
22
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_band
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka Kamei
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-19 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -47,6 +47,9 @@ files:
47
47
  - lib/rails_band/action_controller/event/unpermitted_parameters.rb
48
48
  - lib/rails_band/action_controller/event/write_fragment.rb
49
49
  - lib/rails_band/action_controller/log_subscriber.rb
50
+ - lib/rails_band/action_mailer/event/deliver.rb
51
+ - lib/rails_band/action_mailer/event/process.rb
52
+ - lib/rails_band/action_mailer/log_subscriber.rb
50
53
  - lib/rails_band/action_view/event/render_collection.rb
51
54
  - lib/rails_band/action_view/event/render_partial.rb
52
55
  - lib/rails_band/action_view/event/render_template.rb
@@ -67,7 +70,7 @@ metadata:
67
70
  homepage_uri: https://github.com/yykamei/rails_band
68
71
  source_code_uri: https://github.com/yykamei/rails_band
69
72
  changelog_uri: https://github.com/yykamei/rails_band/blob/main/CHANGELOG.md
70
- post_install_message:
73
+ post_install_message:
71
74
  rdoc_options: []
72
75
  require_paths:
73
76
  - lib
@@ -83,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
86
  version: '0'
84
87
  requirements: []
85
88
  rubygems_version: 3.2.22
86
- signing_key:
89
+ signing_key:
87
90
  specification_version: 4
88
91
  summary: Easy-to-use Rails Instrumentation API
89
92
  test_files: []