Skip to content

Commit

Permalink
Remove framework duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Sep 23, 2015
1 parent 8d2c350 commit 6106e13
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 195 deletions.
158 changes: 0 additions & 158 deletions lib/lotus/mailer.rb
Expand Up @@ -64,7 +64,6 @@ def self.included(base)
class_attribute :configuration

self.configuration = conf.duplicate
self.templates = Hash.new
end

conf.copy!(base)
Expand All @@ -82,163 +81,6 @@ def self.load!
configuration.load!
end

# Duplicate Lotus::Mailer in order to create a new separated instance
# of the framework.
#
# The new instance of the framework will be completely decoupled from the
# original. It will inherit the configuration, but all the changes that
# happen after the duplication, won't be reflected on the other copies.
#
# @return [Module] a copy of Lotus::Mailer
#
# @since 0.1.0
# @api private
#
# @example Basic usage
# require 'lotus/mailer'
#
# module MyApp
# Mailer = Lotus::Mailer.dupe
# end
#
# MyApp::Mailer == Lotus::Mailer # => false
#
# MyApp::Mailer.configuration ==
# Lotus::Mailer.configuration # => false
#
# @example Inheriting configuration
# require 'lotus/mailer'
#
# Lotus::Mailer.configure do
# root '/path/to/root'
# end
#
# module MyApp
# Mailer = Lotus::Mailer.dupe
# end
#
# module MyApi
# Mailer = Lotus::Mailer.dupe
# Mailer.configure do
# root '/another/root'
# end
# end
#
# Lotus::Mailer.configuration.root # => #<Pathname:/path/to/root>
# MyApp::Mailer.configuration.root # => #<Pathname:/path/to/root>
# MyApi::Mailer.configuration.root # => #<Pathname:/another/root>
def self.dupe
dup.tap do |duplicated|
duplicated.configuration = configuration.duplicate
end
end

# Duplicate the framework and generate modules for the target application
#
# @param mod [Module] the Ruby namespace of the application
# @param mailers [String] the optional namespace where the application's
# mailers will live
# @param blk [Proc] an optional block to configure the framework
#
# @return [Module] a copy of Lotus::Mailer
#
# @since 0.1.0
#
# @see Lotus::Mailer#dupe
# @see Lotus::Mailer::Configuration
# @see Lotus::Mailer::Configuration#namespace
#
# @example Basic usage
# require 'lotus/mailer'
#
# module MyApp
# Mailer = Lotus::Mailer.duplicate(self)
# end
#
# module MyApp::Mailers::InvoiceMailer
# class Index
# include MyApp::Mailer
# end
# end
#
# @example Compare code
# require 'lotus/mailer'
#
# module MyApp
# Mailer = Lotus::Mailer.duplicate(self) do
# # ...
# end
# end
#
# # it's equivalent to:
#
# module MyApp
# Mailer = Lotus::Mailer.dupe
#
# module Mailers
# end
#
# Mailer.configure do
# namespace 'MyApp::Mailers'
# end
#
# Mailer.configure do
# # ...
# end
# end
#
# @example Custom mailers module
# require 'lotus/mailer
#
# module MyApp
# Mailer = Lotus::Mailer.duplicate(self, 'Vs')
# end
#
# defined?(MyApp::Mailers) # => nil
# defined?(MyApp::Vs) # => "constant"
#
# # Developers can namespace mailers under Vs
# module MyApp::Vs::InvoiceMailer
# # ...
# end
#
# @example Nil mailers module
# require 'lotus/mailer'
#
# module MyApp
# Mailer = Lotus::Mailer.duplicate(self, nil)
# end
#
# defined?(MyApp::Mailers) # => nil
#
# # Developers can namespace mailers under MyApp
# module MyApp
# # ...
# end
#
# @example Block usage
# require 'lotus/mailer'
#
# module MyApp
# Mailer = Lotus::Mailer.duplicate(self) do
# root '/path/to/root'
# end
# end
#
# Lotus::Mailer.configuration.root # => #<Pathname:.>
# MyApp::Mailer.configuration.root # => #<Pathname:/path/to/root>
def self.duplicate(mod, mailers = 'Mailers', &blk)
dupe.tap do |duplicated|
mod.module_eval %{ module #{ mailers }; end } if mailers

duplicated.configure do
namespace [mod, mailers].compact.join '::'
end

duplicated.configure(&blk) if block_given?
end
end

module ClassMethods
# Delivers a multipart email. It instantiates a mailer and deliver the email.
#
Expand Down
37 changes: 0 additions & 37 deletions test/configuration_test.rb
Expand Up @@ -97,43 +97,6 @@ class PrepareMailer
end
end

describe '#duplicate' do
before do
@configuration.root 'test'
@configuration.add_mailer( InvoiceMailer )
@configuration.prepare { include Kernel }

@config = @configuration.duplicate
end

it 'returns a copy of the configuration' do
@config.root.must_equal @configuration.root
@config.modules.must_equal @configuration.modules
@config.mailers.must_be_empty
end

it "doesn't affect the original configuration" do
@config.root '.'
@config.add_mailer(RenderMailer)
@config.prepare { include Comparable }

@config.root.must_equal Pathname.new('.').realpath
@config.mailers.must_include RenderMailer
@config.modules.size.must_equal 2

@configuration.root.must_equal Pathname.new('test').realpath
@configuration.mailers.must_include InvoiceMailer
@configuration.mailers.wont_include RenderMailer
end

it 'duplicates namespace' do
@configuration.namespace(InvoiceMailer)
conf = @configuration.duplicate

conf.namespace.must_equal(InvoiceMailer)
end
end

# describe '#reset!' do
# before do
# @configuration.root 'test'
Expand Down

0 comments on commit 6106e13

Please sign in to comment.