module PublicActivity

public_activity keeps track of changes made to models and allows you to display them to the users.

Check {PublicActivity::Tracked::ClassMethods#tracked} for more details about customizing and specifying ownership to users.

This file provides functionality for testing your code with public_activity activated or deactivated. This file should only be required in test/spec code!

To enable PublicActivity testing capabilities do:

require 'public_activity/testing'

Provides a shortcut from views to the rendering method.

Constants

VERSION

A constant with gem's version

Public Class Methods

config() click to toggle source

Returns PublicActivity's configuration object. @since 0.5.0

# File lib/public_activity.rb, line 45
def self.config
  @@config ||= PublicActivity::Config.instance
end
enabled=(value) click to toggle source

Switches PublicActivity on or off. @param value [Boolean] @since 0.5.0

# File lib/public_activity.rb, line 31
def self.enabled=(value)
  config.enabled(value)
end
enabled?() click to toggle source

Returns `true` if PublicActivity is on, `false` otherwise. Enabled by default. @return [Boolean] @since 0.5.0

# File lib/public_activity.rb, line 39
def self.enabled?
  config.enabled
end
get_controller() click to toggle source

Getter for accessing the controller instance

# File lib/public_activity/utility/store_controller.rb, line 11
def get_controller
  Thread.current[:public_activity_controller]
end
inherit_orm(model="Activity") click to toggle source

Method used to choose which ORM to load when PublicActivity::Activity class is being autoloaded

# File lib/public_activity.rb, line 51
def self.inherit_orm(model="Activity")
  orm = PublicActivity.config.orm
  require "public_activity/orm/#{orm.to_s}"
  "PublicActivity::ORM::#{orm.to_s.classify}::#{model}".constantize
end
resolve_value(context, thing) click to toggle source

Used to smartly transform value from metadata to data. Accepts Symbols, which it will send against context. Accepts Procs, which it will execute with controller and context. @since 0.4.0

# File lib/public_activity/common.rb, line 11
def self.resolve_value(context, thing)
  case thing
  when Symbol
    context.__send__(thing)
  when Proc
    thing.call(PublicActivity.get_controller, context)
  else
    thing
  end
end
set_controller(controller) click to toggle source

Setter for remembering controller instance

# File lib/public_activity/utility/store_controller.rb, line 6
def set_controller(controller)
  Thread.current[:public_activity_controller] = controller
end
with_tracking() { || ... } click to toggle source

Execute the code block with PublicActiviy active

Example usage:

PublicActivity.with_tracking do
  # your test code here
end
# File lib/public_activity/testing.rb, line 16
def self.with_tracking
  current = PublicActivity.config.enabled
  PublicActivity.config.enabled(true)
  yield
ensure
  PublicActivity.config.enabled(current)
end
without_tracking() { || ... } click to toggle source

Execute the code block with PublicActiviy deactive

Example usage:

PublicActivity.without_tracking do
  # your test code here
end
# File lib/public_activity/testing.rb, line 30
def self.without_tracking
  current = PublicActivity.enabled?
  PublicActivity.config.enabled(false)
  yield
ensure
  PublicActivity.config.enabled(current)
end