module ActivityNotification

Constants

VERSION

Public Class Methods

cast_to_indifferent_hash(hash = {}) click to toggle source

Casts to indifferent hash @param [ActionController::Parameters, Hash] hash @return [HashWithIndifferentAccess] Converted indifferent hash

# File lib/activity_notification/common.rb, line 53
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
config() click to toggle source

Returns configuration object of ActivityNotification.

# File lib/activity_notification.rb, line 27
def self.config
  @config ||= ActivityNotification::Config.new
end
configure() { |config| ... } click to toggle source

Sets global configuration options for ActivityNotification. All available options and their defaults are in the example below: @example 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
# File lib/activity_notification.rb, line 44
def self.configure
  yield(config) if block_given?
  autoload :Association, "activity_notification/orm/#{ActivityNotification.config.orm}"
end
gem_version() click to toggle source

Returns the version of the currently loaded ActivityNotification as a Gem::Version

# File lib/activity_notification/gem_version.rb, line 3
def self.gem_version
  Gem::Version.new VERSION
end
get_controller() click to toggle source

Getter for accessing the controller instance

@return [NotificationsController, NotificationsWithDeviseController]] Controller instance to be set

# File lib/activity_notification/controllers/store_controller.rb, line 14
def get_controller
  Thread.current[:activity_notification_controller]
end
inherit_orm(model) click to toggle source

Method used to choose which ORM to load when ActivityNotification::Notification class or ActivityNotification::Subscription class are being autoloaded

# File lib/activity_notification.rb, line 52
def self.inherit_orm(model)
  orm = ActivityNotification.config.orm
  require "activity_notification/orm/#{orm}"
  "ActivityNotification::ORM::#{orm.to_s.classify}::#{model}".constantize
end
resolve_value(context, thing, *args) click to toggle source

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.

@param [Object] context Context to resolve parameter, which is usually target or notificable model @param [Symbol, Proc, Hash, Object] thing Symbol or Proc to resolve parameter @param [Array] args Arguments to pass to thing as method @return [Object] Resolved parameter value

# 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
      if args.last.kind_of?(Hash)
        symbol_method.call(ActivityNotification.get_controller, *args[0...-1], **args[-1])
      else
        symbol_method.call(ActivityNotification.get_controller, *args)
      end
    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)
    elsif thing.arity > 0
      thing.call(context)
    else
      thing.call
    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) click to toggle source

Setter for remembering controller instance

@param [NotificationsController, NotificationsWithDeviseController] controller Controller instance to set @return [NotificationsController, NotificationsWithDeviseController]] Controller instance to be set

# File lib/activity_notification/controllers/store_controller.rb, line 7
def set_controller(controller)
  Thread.current[:activity_notification_controller] = controller
end