Module: ActivityNotification

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Defined in:
lib/activity_notification/rails.rb,
lib/activity_notification.rb,
lib/activity_notification/common.rb,
lib/activity_notification/config.rb,
lib/activity_notification/models.rb,
lib/activity_notification/version.rb,
lib/activity_notification/renderable.rb,
lib/activity_notification/mailers/helpers.rb,
lib/activity_notification/models/notification.rb,
lib/activity_notification/roles/acts_as_group.rb,
lib/activity_notification/helpers/view_helpers.rb,
lib/activity_notification/roles/acts_as_common.rb,
lib/activity_notification/roles/acts_as_target.rb,
lib/activity_notification/apis/notification_api.rb,
lib/activity_notification/models/concerns/group.rb,
lib/activity_notification/models/concerns/target.rb,
lib/activity_notification/roles/acts_as_notifier.rb,
lib/activity_notification/models/concerns/notifier.rb,
lib/activity_notification/roles/acts_as_notifiable.rb,
lib/activity_notification/models/concerns/notifiable.rb,
lib/generators/activity_notification/views_generator.rb,
lib/activity_notification/helpers/polymorphic_helpers.rb,
lib/activity_notification/controllers/store_controller.rb,
lib/generators/activity_notification/install_generator.rb,
lib/generators/activity_notification/controllers_generator.rb,
app/controllers/activity_notification/notifications_controller.rb,
lib/generators/activity_notification/migration/migration_generator.rb,
lib/generators/activity_notification/notification/notification_generator.rb,
app/controllers/activity_notification/notifications_with_devise_controller.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ActsAsCommon, ActsAsGroup, ActsAsNotifiable, ActsAsNotifier, ActsAsTarget, Common, Generators, Group, Mailers, Models, Notifiable, NotificationApi, Notifier, PolymorphicHelpers, Renderable, StoreController, Target, ViewHelpers Classes: Config, Engine, Mailer, Notification, NotificationsController, NotificationsWithDeviseController

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.cast_to_indifferent_hash(hash = {}) ⇒ HashWithIndifferentAccess

Casts to indifferent hash

Parameters:

Returns:

  • Converted indifferent hash



47
48
49
50
51
52
53
# File 'lib/activity_notification/common.rb', line 47

def self.cast_to_indifferent_hash(hash = {})
  # This is the typical (not-ActionView::TestCase) code path.
  hash = hash.to_unsafe_h if hash.respond_to?(:to_unsafe_h)
  # In Rails 5 to_unsafe_h returns a HashWithIndifferentAccess, in Rails 4 it returns Hash
  hash = hash.with_indifferent_access if hash.instance_of? Hash
  hash
end

.configObject

Returns configuration object of ActivityNotification.



26
27
28
# File 'lib/activity_notification.rb', line 26

def self.config
  @config ||= ActivityNotification::Config.new
end

.configure {|config| ... } ⇒ Object

Sets global configuration options for ActivityNotification. All available options and their defaults are in the example below:

Examples:

Initializer for Rails

ActivityNotification.configure do |config|
  config.enabled            = true
  config.table_name         = "notifications"
  config.email_enabled      = false
  config.mailer_sender      = nil
  config.mailer             = 'ActivityNotification::Mailer'
  config.parent_mailer      = 'ActionMailer::Base'
  config.parent_controller  = 'ApplicationController'
  config.opened_index_limit = 10
end

Yields:



43
44
45
# File 'lib/activity_notification.rb', line 43

def self.configure(&block)
  yield(config) if block_given?
end

.get_controllerNotificationsController, NotificationsWithDeviseController

Getter for accessing the controller instance

Returns:

  • ] Controller instance to be set



14
15
16
# File 'lib/activity_notification/controllers/store_controller.rb', line 14

def get_controller
  Thread.current[:activity_notification_controller]
end

.resolve_value(context, thing, *args) ⇒ Object

Used to transform value from metadata to data. Accepts Symbols, which it will send against context. Accepts Procs, which it will execute with controller and context. Both Symbols and Procs will be passed arguments of this method. Also accepts Hash of these Symbols or Procs. If any other value will be passed, returns original value.

Parameters:

  • Context to resolve parameter, which is usually target or notificable model

  • Symbol or Proc to resolve parameter

  • Arguments to pass to thing as method

Returns:

  • Resolved parameter value



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/activity_notification/common.rb', line 14

def self.resolve_value(context, thing, *args)
  case thing
  when Symbol
    symbol_method = context.method(thing)
    if symbol_method.arity > 1
      symbol_method.call(ActivityNotification.get_controller, *args)
    elsif symbol_method.arity > 0
      symbol_method.call(ActivityNotification.get_controller)
    else
      symbol_method.call
    end
  when Proc
    if thing.arity > 2
      thing.call(ActivityNotification.get_controller, context, *args)
    elsif thing.arity > 1
      thing.call(ActivityNotification.get_controller, context)
    else
      thing.call(context)
    end
  when Hash
    thing.dup.tap do |hash|
      hash.each do |key, value|
        hash[key] = ActivityNotification.resolve_value(context, value, *args)
      end
    end
  else
    thing
  end
end

.set_controller(controller) ⇒ NotificationsController, NotificationsWithDeviseController

Setter for remembering controller instance

Parameters:

  • Controller instance to set

Returns:

  • ] Controller instance to be set



7
8
9
# File 'lib/activity_notification/controllers/store_controller.rb', line 7

def set_controller(controller)
  Thread.current[:activity_notification_controller] = controller
end