Sha256: db458b48316ed0288d4b772f2d1ae2ef27dbf0f6bc13c686b6cd79d7ed3bb1e5

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

require 'rails/railtie'

module SweetNotifications
  # Rails Railtie integration
  module Railtie
    extend self
    # Attach LogSubscriber and ControllerRuntime to a notifications namespace
    #
    # @param name [Symbol] Notifications namespace
    # @param log_subscriber [LogSubscriber] subscriber to be attached
    # @param controller_runtime [Module] mixin that logs runtime
    def initialize_rails(name, log_subscriber, controller_runtime)
      log_subscriber.attach_to name.to_sym
      ActiveSupport.on_load(:action_controller) do
        include controller_runtime
      end
    end

    # Create a Railtie for LogSubscriber and ControllerRuntime mixin
    #
    # @param name [Symbol] Notifications namespace
    # @param log_subscriber [LogSubscriber] subscriber to be attached
    # @param controller_runtime [Module] mixin that logs runtime
    # @return [Rails::Railtie] Rails initializer
    def railtie(name, log_subscriber, controller_runtime)
      Class.new(Rails::Railtie) do
        railtie_name name
        initializer "#{name}.notifications" do
          SweetNotifications::Railtie.initialize_rails(name,
                                                       log_subscriber,
                                                       controller_runtime)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sweet_notifications-1.1.1 lib/sweet_notifications/railtie.rb
sweet_notifications-1.1.0 lib/sweet_notifications/railtie.rb
sweet_notifications-1.0.1 lib/sweet_notifications/railtie.rb
sweet_notifications-1.0.0 lib/sweet_notifications/railtie.rb
sweet_notifications-0.2.1 lib/sweet_notifications/railtie.rb
sweet_notifications-0.2.0 lib/sweet_notifications/railtie.rb
sweet_notifications-0.1.0 lib/sweet_notifications/railtie.rb