lib/emailbutler.rb in emailbutler-0.7.6 vs lib/emailbutler.rb in emailbutler-0.8.1

- old
+ new

@@ -4,41 +4,52 @@ require 'emailbutler/version' require 'emailbutler/engine' require 'emailbutler/configuration' require 'emailbutler/dsl' -require 'emailbutler/webhooks/receiver' require 'emailbutler/helpers' require 'emailbutler/mailers/helpers' +require 'emailbutler/container' module Emailbutler extend self extend Forwardable - # Public: Given an adapter returns a handy DSL to all the emailbutler goodness. - def new(adapter) - DSL.new(adapter) - end - # Public: Configure emailbutler. # + # require 'emailbutler/adapters/active_record' + # # Emailbutler.configure do |config| # config.adapter = Emailbutler::Adapters::ActiveRecord.new + # config.providers = %i[sendgrid] # end # def configure + ActiveSupport::Deprecation.new.warn( + 'Webhook endpoint should receive provider name in params. ' \ + 'Please update webhook url in settings of your SMTP provider.' \ + 'Webhook without provider in params will be removed soon.' + ) + yield configuration + + configuration.validate end # Public: Returns Emailbutler::Configuration instance. def configuration - @configuration ||= Configuration.new + return Emailbutler::Container.resolve(:configuration) if Emailbutler::Container.key?(:configuration) + + Emailbutler::Container.register(:configuration) { Configuration.new } + Emailbutler::Container.resolve(:configuration) end - # Public: Default per thread emailbutler instance if configured. - # Returns Emailbutler::DSL instance. + # Public: Returns Emailbutler::DSL instance. def instance - Thread.current[:emailbutler_instance] ||= new(configuration.adapter) + return Emailbutler::Container.resolve(:instance) if Emailbutler::Container.key?(:instance) + + Emailbutler::Container.register(:instance) { DSL.new(configuration.adapter) } + Emailbutler::Container.resolve(:instance) end # Public: All the methods delegated to instance. These should match the interface of Emailbutler::DSL. def_delegators :instance, :adapter, :build_message, :set_message_attribute, :save_message, :find_message_by,