Skip to content

Commit 78d0e7a

Browse files
committed
Fix namespaces
1 parent 094dfa8 commit 78d0e7a

File tree

6 files changed

+24
-27
lines changed

6 files changed

+24
-27
lines changed

lib/generators/supermail/email/email_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'rails/generators/named_base'
44

55
module Supermail
6-
class EmailGenerator < Rails::Generators::NamedBase
6+
class EmailGenerator < ::Rails::Generators::NamedBase
77
source_root File.expand_path('templates', __dir__)
88

99
desc "Generate a new email class"
@@ -22,4 +22,4 @@ def class_name
2222
name.camelize
2323
end
2424
end
25-
end
25+
end

lib/generators/supermail/install/install_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'rails/generators/base'
44

55
module Supermail
6-
class InstallGenerator < Rails::Generators::Base
6+
class InstallGenerator < ::Rails::Generators::Base
77
source_root File.expand_path('templates', __dir__)
88

99
desc "Install Supermail in a Rails application"
@@ -16,4 +16,4 @@ def create_emails_directory
1616
empty_directory 'app/emails'
1717
end
1818
end
19-
end
19+
end

lib/generators/supermail/install/templates/application_email.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class ApplicationEmail < Supermail::Base
1+
class ApplicationEmail < Supermail::Rails::Base
22
def from = "website@example.com"
33

44
def body

lib/supermail.rb

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
# frozen_string_literal: true
22

33
require_relative "supermail/version"
4-
require 'action_mailer'
4+
require "action_mailer"
55

66
module Supermail
77
class Error < StandardError; end
88

9-
class Base
10-
delegate :deliver, :deliver_now, :deliver_later, to: :message_delivery
9+
module Rails
10+
class Base
11+
delegate :deliver, :deliver_now, :deliver_later, to: :message_delivery
1112

12-
def to = nil
13-
def from = nil
14-
def subject = nil
15-
def body = ""
13+
def to = nil
14+
def from = nil
15+
def subject = nil
16+
def body = ""
1617

17-
def message
18-
message_delivery.message
19-
end
18+
def message
19+
message_delivery.message
20+
end
2021

21-
def message_delivery
22-
ActionMailer::Base.mail(to:, from:, subject:, body:)
22+
def message_delivery
23+
ActionMailer::Base.mail(to:, from:, subject:, body:)
24+
end
2325
end
2426
end
2527
end
26-
27-
# Load generators only when Rails is available
28-
if defined?(::Rails)
29-
require 'rails'
30-
end

spec/generators/install_generator_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
RSpec.describe Supermail::InstallGenerator, type: :generator do
77
tests Supermail::InstallGenerator
8-
8+
99
INSTALL_DESTINATION_PATH = Pathname.new(__dir__).join("../tmp/generators")
1010
destination INSTALL_DESTINATION_PATH.to_s
11-
11+
1212
before { prepare_destination }
1313
after { FileUtils.rm_rf(INSTALL_DESTINATION_PATH) }
1414

@@ -17,7 +17,7 @@
1717

1818
describe "app/emails/application_email.rb" do
1919
subject { File.read(INSTALL_DESTINATION_PATH.join("app/emails/application_email.rb")) }
20-
it { is_expected.to match(/class ApplicationEmail < Supermail::Base/) }
20+
it { is_expected.to match(/class ApplicationEmail < Supermail::Rails::Base/) }
2121
it { is_expected.to match(/def from = "website@example.com"/) }
2222
it { is_expected.to match(/The Example.com Team/) }
2323
end
@@ -27,4 +27,4 @@
2727
it { is_expected.to be true }
2828
end
2929
end
30-
end
30+
end

spec/supermail_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "spec_helper"
44

5-
class ExampleMailer < Supermail::Base
5+
class ExampleMailer < Supermail::Rails::Base
66
def initialize(to:, from:, subject:, body:)
77
@to = to
88
@from = from

0 commit comments

Comments
 (0)