letter_thief 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bff6011c6899c346bc0de0779fa7b95549d51ee83b78567b77ebecbdc290c4a
4
- data.tar.gz: 8804964cea6bf766ec28472dc5fd9f6b41f2f2a32d89b37b7981870b173c7f49
3
+ metadata.gz: 6de7e8358d331ad26b618b894144be9744bde140e2ff669af34cb508e442087d
4
+ data.tar.gz: 16db7cdb1815bdf9a0ee5bcfc675a3c8e543193ebdfeb73f194c5cf579a258cb
5
5
  SHA512:
6
- metadata.gz: bae87c979366a349a3965c636ea86eb9592c22a9a68241902abe4e27572bd285192ba05121d601bac86b2b6d1623632a17b72957ac06d585911ec9cf0a6b63e9
7
- data.tar.gz: 7473e046f6c52bb33df9bcb2fed97efdda306150cf5c74096dd0ffbc647fd9c008bfcfc3647a038e530973e1edd324ef410407ad7a2c8688dd306642cb419cb2
6
+ metadata.gz: 1d86fcae20c7ce2f05b3755e90e6bddcd84cfeb1b130c1f37c46db0458d0ba58328b78469e60bd1e945106a15a505c115bcf8ac2dfa4c2752481302824096b28
7
+ data.tar.gz: 83ef8fe689e0436f7609543e599a874e5c76e87d6df868d365211993778a053d4fc94244623c72fa34fe1adb54d4a90f3aa6e7a2df7d5b16622889d74880a955
data/README.md CHANGED
@@ -26,6 +26,7 @@ If you used `letter_opener` in the past you know how nice it is to have
26
26
  the sent emails opened automatically in your Browser when working locally.
27
27
  LetterThief supports this as well with the very same mechanism, but `launchy` is not a direct dependency.
28
28
  If you add Launchy on your Gemfile, emails will be opened right away once sent.
29
+ This can be disabled with `LetterThief.open_sent_emails = false`.
29
30
 
30
31
  Since emails are persisted on the Database it means you can use this also on Heroku, deplo.io, or other PaaS where you
31
32
  don't have a disk. No need for an external service like Mailtrap (amazing service!) anymore.
@@ -57,6 +58,24 @@ authenticate :user, ->(user) { user&.administrator? } do
57
58
  end
58
59
  ```
59
60
 
61
+ ### Authentication
62
+
63
+ Alternatively, you can provide your own authentication mechanism by specifying a different controller as the base class
64
+ for LetterThief's controllers. By default, LetterThief's controllers extend `::ApplicationController`, but you can change
65
+ this easily:
66
+
67
+ ```ruby
68
+ # config/initializers/letter_thief.rb
69
+ Rails.application.configure do
70
+ LetterThief.base_controller_class = "AdminController"
71
+ end
72
+ ```
73
+
74
+ This is useful if you have a custom controller (like `AdminController`) that already handles authentication via
75
+ `before_action` callbacks.
76
+
77
+ ### Delivery Method
78
+
60
79
  If you want to stop sending emails, you can use it also as delivery method:
61
80
 
62
81
  ```ruby
@@ -74,12 +93,25 @@ end
74
93
 
75
94
  and LetterThief will open emails directly in your Browser like Letter Opener.
76
95
 
96
+ If `launchy` is in your Gemfile for other reasons and you don't want emails to be opened automatically, you can disable
97
+ it:
98
+
99
+ ```ruby
100
+ # config/initializers/letter_thief.rb
101
+ LetterThief.open_sent_emails = false
102
+ ```
103
+
77
104
  ### Separate database
78
105
 
79
- If you'd like to store your emails on a separate database, you can configure it via:
106
+ If you'd like to store your emails on a separate database, you can configure it in an initializer:
80
107
 
81
- `config.letter_thief.connects_to = {database: {writing: :letter_thief}}` and of course you'll need a separate database
82
- configuration. Here is an example:
108
+ ```ruby
109
+ # config/initializers/letter_thief.rb
110
+ LetterThief.connects_to = {database: {writing: :letter_thief}}
111
+ ```
112
+
113
+ The value is passed as is to Rails' `connects_to`, so you can also configure shards or a separate reading database.
114
+ Of course you'll need a separate database configuration. Here is an example:
83
115
 
84
116
  ```yml
85
117
  development:
@@ -92,6 +124,20 @@ development:
92
124
  migrations_paths: db/letter_thief_migrate
93
125
  ```
94
126
 
127
+ Move the migration generated by `rails generate letter_thief:install` to `db/letter_thief_migrate` so that the
128
+ `letter_thief_email_messages` table is created on the separate database. Attachments still use ActiveStorage on your
129
+ primary database.
130
+
131
+ ### Enable/Disable Observer
132
+
133
+ By default, LetterThief observes all emails sent by your application and logs them to the database. You can disable this behavior by setting:
134
+
135
+ ```ruby
136
+ LetterThief.observer_enabled = false
137
+ ```
138
+
139
+ This is useful when you want to disable email logging in production or only enable it when debugging specific issues. You can configure this per environment in `config/environments/production.rb` or toggle it dynamically in the Rails console.
140
+
95
141
  ## Varia
96
142
 
97
143
  > [!NOTE]
@@ -123,7 +169,6 @@ TARGET_DB=mysql bin/test #mysql
123
169
 
124
170
  You can also sping up a dummy app with `bin/rails server` and work there.
125
171
 
126
-
127
172
  ## Contributing
128
173
 
129
174
  Bug reports and pull requests are welcome on GitHub at https://github.com/coorasse/letter_thief.
@@ -1,4 +1,4 @@
1
1
  module LetterThief
2
- class ApplicationController < ActionController::Base
2
+ class ApplicationController < LetterThief.base_controller_class.constantize
3
3
  end
4
4
  end
@@ -1,5 +1,7 @@
1
1
  module LetterThief
2
2
  class ApplicationRecord < ActiveRecord::Base
3
3
  self.abstract_class = true
4
+
5
+ connects_to(**LetterThief.connects_to) if LetterThief.connects_to
4
6
  end
5
7
  end
@@ -2,14 +2,12 @@ module LetterThief
2
2
  class EmailMessage < ApplicationRecord
3
3
  self.table_name = "letter_thief_email_messages"
4
4
 
5
- connects_to(**LetterThief.connects_to) if LetterThief.connects_to
6
-
7
5
  if LetterThief.activestorage_available?
8
6
  has_many_attached :attachments
9
7
  has_one_attached :raw_email
10
8
  end
11
9
 
12
- unless ActiveRecord::Base.connection.adapter_name.downcase.include?("postgresql")
10
+ unless connection.adapter_name.downcase.include?("postgresql")
13
11
  serialize :to, coder: JSON, type: Array
14
12
  serialize :from, coder: JSON, type: Array
15
13
  serialize :sender, coder: JSON, type: Array
@@ -16,7 +16,7 @@ module LetterThief
16
16
  scope = EmailMessage.order(intercepted_at: :desc)
17
17
 
18
18
  if query.present?
19
- adapter = ActiveRecord::Base.connection.adapter_name.downcase
19
+ adapter = EmailMessage.connection.adapter_name.downcase
20
20
  scope = if adapter.include?("postgresql")
21
21
  scope.where(<<~SQL.squish, q: "%#{query}%")
22
22
  subject ILIKE :q
@@ -6,8 +6,15 @@ module LetterThief
6
6
  end
7
7
 
8
8
  def deliver!(mail)
9
+ delivered_mail = Observer.delivered_email(mail)
10
+ open_in_browser(delivered_mail) if LetterThief.open_sent_emails
11
+ end
12
+
13
+ private
14
+
15
+ def open_in_browser(delivered_mail)
9
16
  require "launchy"
10
- ::Launchy.open(LetterThief::Engine.routes.url_helpers.email_message_url(Observer.delivered_email(mail), Rails.configuration.action_mailer.default_url_options))
17
+ ::Launchy.open(LetterThief::Engine.routes.url_helpers.email_message_url(delivered_mail, Rails.configuration.action_mailer.default_url_options))
11
18
  rescue LoadError
12
19
  puts "WARNING: LetterThief requires the 'launchy' gem to open the email in a web browser. Add it to your Gemfile."
13
20
  end
@@ -6,7 +6,7 @@ module LetterThief
6
6
  isolate_namespace LetterThief
7
7
 
8
8
  initializer "letter_thief.add_observer" do
9
- unless Rails.application.config.action_mailer.delivery_method == :letter_thief
9
+ if LetterThief.observer_enabled && Rails.application.config.action_mailer.delivery_method != :letter_thief
10
10
  ActiveSupport.on_load(:action_mailer) do
11
11
  ActionMailer::Base.register_observer(LetterThief::Observer)
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module LetterThief
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/letter_thief.rb CHANGED
@@ -3,6 +3,9 @@ require "letter_thief/engine"
3
3
 
4
4
  module LetterThief
5
5
  mattr_accessor :connects_to
6
+ mattr_accessor :base_controller_class, default: "::ApplicationController"
7
+ mattr_accessor :observer_enabled, default: true
8
+ mattr_accessor :open_sent_emails, default: true
6
9
 
7
10
  def self.used_activestorage_space
8
11
  ActiveStorage::Blob
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_thief
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-01-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -60,7 +59,6 @@ metadata:
60
59
  homepage_uri: https://github.com/coorasse/letter_thief
61
60
  source_code_uri: https://github.com/coorasse/letter_thief
62
61
  changelog_uri: https://github.com/coorasse/letter_thief/blob/main/CHANGELOG.md
63
- post_install_message:
64
62
  rdoc_options: []
65
63
  require_paths:
66
64
  - lib
@@ -75,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
73
  - !ruby/object:Gem::Version
76
74
  version: '0'
77
75
  requirements: []
78
- rubygems_version: 3.3.27
79
- signing_key:
76
+ rubygems_version: 3.6.9
80
77
  specification_version: 4
81
78
  summary: Log emails in Rails and visualize them.
82
79
  test_files: []