Module: SweetNotifications::Railtie

Extended by:
Railtie
Included in:
SweetNotifications, Railtie
Defined in:
lib/sweet_notifications/railtie.rb

Overview

Rails Railtie integration

Instance Method Summary collapse

Instance Method Details

#initialize_rails(name, log_subscriber, controller_runtime) ⇒ Object

Attach LogSubscriber and ControllerRuntime to a notifications namespace

Parameters:

  • name (Symbol)

    Notifications namespace

  • log_subscriber (LogSubscriber)

    subscriber to be attached

  • controller_runtime (Module)

    mixin that logs runtime



12
13
14
15
16
17
# File 'lib/sweet_notifications/railtie.rb', line 12

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

#railtie(name, log_subscriber, controller_runtime) ⇒ Rails::Railtie

Create a Railtie for LogSubscriber and ControllerRuntime mixin

Parameters:

  • name (Symbol)

    Notifications namespace

  • log_subscriber (LogSubscriber)

    subscriber to be attached

  • controller_runtime (Module)

    mixin that logs runtime

Returns:

  • (Rails::Railtie)

    Rails initializer



25
26
27
28
29
30
31
32
33
34
# File 'lib/sweet_notifications/railtie.rb', line 25

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