Module: PublicActivity

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Defined in:
lib/public_activity.rb,
lib/public_activity/model.rb,
lib/public_activity/common.rb,
lib/public_activity/config.rb,
lib/public_activity/testing.rb,
lib/public_activity/version.rb,
lib/public_activity/activity.rb,
lib/public_activity/renderable.rb,
lib/public_activity/roles/tracked.rb,
lib/public_activity/models/adapter.rb,
lib/public_activity/actions/update.rb,
lib/public_activity/models/activist.rb,
lib/public_activity/models/activity.rb,
lib/public_activity/models/trackable.rb,
lib/public_activity/actions/creation.rb,
lib/public_activity/roles/deactivatable.rb,
lib/public_activity/orm/mongoid/adapter.rb,
lib/public_activity/actions/destruction.rb,
lib/public_activity/orm/mongoid/activist.rb,
lib/public_activity/utility/view_helpers.rb,
lib/public_activity/orm/mongoid/activity.rb,
lib/public_activity/orm/mongoid/trackable.rb,
lib/public_activity/utility/store_controller.rb,
lib/public_activity/orm/mongo_mapper/adapter.rb,
lib/public_activity/orm/mongo_mapper/activist.rb,
lib/public_activity/orm/active_record/adapter.rb,
lib/public_activity/orm/mongo_mapper/activity.rb,
lib/public_activity/orm/mongo_mapper/trackable.rb,
lib/public_activity/orm/active_record/activist.rb,
lib/public_activity/orm/active_record/activity.rb,
lib/public_activity/orm/active_record/trackable.rb,
lib/generators/public_activity/activity/activity_generator.rb,
lib/generators/public_activity/migration/migration_generator.rb

Overview

Provides a shortcut from views to the rendering method.

Defined Under Namespace

Modules: Activist, Common, Creation, Deactivatable, Destruction, Generators, Model, ORM, Renderable, StoreController, Trackable, Tracked, Update, ViewHelpers Classes: Activity, Adapter, Config, DeprecatedError, NoKeyProvided

Constant Summary collapse

VERSION =

A constant with gem's version

'2.0'
Finalizer =

Lambda called after the thread is destroyed.

lambda { |id|
  @@controllers.delete id
}
@@controllers =
Hash.new

Class Method Summary collapse

Class Method Details

.configObject

Returns PublicActivity's configuration object.

Since:

  • 0.5.0


45
46
47
# File 'lib/public_activity.rb', line 45

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

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

Lets you set global configuration options.

All available options and their defaults are in the example below:

Examples:

Initializer for Rails

PublicActivity.configure do |config|
  config.orm         = :active_record
  config.enabled     = false
  config.table_name  = "activities"
end

Yields:


58
59
60
# File 'lib/public_activity.rb', line 58

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

.enabled=(value) ⇒ Object

Switches PublicActivity on or off.

Parameters:

  • value (Boolean)

Since:

  • 0.5.0


31
32
33
# File 'lib/public_activity.rb', line 31

def self.enabled=(value)
  PublicActivity.config.enabled = value
end

.enabled?Boolean

Returns true if PublicActivity is on, false otherwise. Enabled by default.

Returns:

  • (Boolean)

Since:

  • 0.5.0


39
40
41
# File 'lib/public_activity.rb', line 39

def self.enabled?
  !!PublicActivity.config.enabled
end

.get_controllerObject

Getter for accessing the controller instance


19
20
21
# File 'lib/public_activity/utility/store_controller.rb', line 19

def get_controller
  @@controllers[Thread.current.object_id]
end

.inherit_orm(model = "Activity") ⇒ Object

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


64
65
66
67
68
# File 'lib/public_activity.rb', line 64

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) ⇒ Object

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


9
10
11
12
13
14
15
16
17
18
# File 'lib/public_activity/common.rb', line 9

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) ⇒ Object

Setter for remembering controller instance


11
12
13
14
15
16
# File 'lib/public_activity/utility/store_controller.rb', line 11

def set_controller(controller)
  unless @@controllers.has_key?(Thread.current.object_id)
    ObjectSpace.define_finalizer Thread.current, Finalizer
  end if RUBY_VERSION != "1.9.3"
  @@controllers[Thread.current.object_id] = controller
end

.with_trackingObject

Execute the code block with PublicActiviy active

Example usage: PublicActivity.with_tracking do # your test code here end


14
15
16
17
18
19
20
# File 'lib/public_activity/testing.rb', line 14

def self.with_tracking
  current = PublicActivity.enabled?
  PublicActivity.enabled = true
  yield
ensure
  PublicActivity.enabled = current
end

.without_trackingObject

Execute the code block with PublicActiviy deactive

Example usage: PublicActivity.without_tracking do # your test code here end


28
29
30
31
32
33
34
# File 'lib/public_activity/testing.rb', line 28

def self.without_tracking
  current = PublicActivity.enabled?
  PublicActivity.enabled = false
  yield
ensure
  PublicActivity.enabled = current
end