Skip to content

Commit

Permalink
Merge pull request #1002 from skade/lazy-mail-without-autoload
Browse files Browse the repository at this point in the history
Lazily load the mail gem without autoload
  • Loading branch information
nesquena committed Jan 11, 2013
2 parents ab9f4d3 + c3c0b90 commit 43db53b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
12 changes: 6 additions & 6 deletions padrino-mailer/lib/padrino-mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class << self
#
# @api public
def registered(app)
# lazily autoload heavy mail and it's padrino extension if ruby is MRI19
if RUBY_VERSION =~ /^1\.9/ && RUBY_ENGINE == 'ruby'
autoload :Mail, 'padrino-mailer/ext'
else
require 'padrino-mailer/ext'
end
require 'padrino-mailer/base'
require 'padrino-mailer/helpers'
require 'padrino-mailer/mime'
# This lazily loads the mail gem, due to its long require time.
app.set :_padrino_mailer, proc {
require 'mail'
require 'padrino-mailer/ext'
app._padrino_mailer = Mail
}
app.helpers Padrino::Mailer::Helpers
end
alias :included :registered
Expand Down
2 changes: 1 addition & 1 deletion padrino-mailer/lib/padrino-mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def initialize(app, name, &block) # @private
def email(name, &block)
raise "The email '#{name}' is already defined" if self.messages[name].present?
self.messages[name] = Proc.new { |*attrs|
message = Mail::Message.new(self.app)
message = app.settings._padrino_mailer::Message.new(self.app)
message.defaults = self.defaults if self.defaults.any?
message.delivery_method(*delivery_settings)
message.instance_exec(*attrs, &block)
Expand Down
2 changes: 0 additions & 2 deletions padrino-mailer/lib/padrino-mailer/ext.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'mail'

module Mail # @private
class Message # @private
include Sinatra::Templates
Expand Down
2 changes: 1 addition & 1 deletion padrino-mailer/lib/padrino-mailer/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def deliver(mailer_name, message_name, *attributes)
#
# @api public
def email(mail_attributes={}, &block)
message = Mail::Message.new(self)
message = _padrino_mailer::Message.new(self)
message.delivery_method(*delivery_settings)
message.instance_eval(&block) if block_given?
mail_attributes.reverse_merge(mailer_defaults) if respond_to?(:mailer_defaults)
Expand Down

0 comments on commit 43db53b

Please sign in to comment.