Module: ActsAsApprovable::Ownership

Defined in:
lib/acts_as_approvable/ownership.rb

Overview

This module provides the Approval class with the ability to assign records as an “owner” of the approval. This is especially useful for tracking purposes when you require it, and can be beneficial when you have an approval queue with a high rate of insertions.

By default the ownership functionality will reference a model named ‘User` and will allow any user to take ownership of an approval.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(options = {}, &block) ⇒ Object

Configure approvals to allow ownership by a User model.

If a block is given it will be applied to Approval at the class level, allowing you to override functionality on the fly.

Parameters:

  • options (Hash) (defaults to: {})

    a hash of options for configuration

Options Hash (options):

  • :model (Object)

    the model being used for Approval records (defaults to ‘Approval`).

  • :owner (Object)

    the model being used for owner records (defaults to ‘User`).

  • :source (Object)

    class used to override retrieval of owner records.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acts_as_approvable/ownership.rb', line 21

def self.configure(options = {}, &block)
  approval = options.delete(:model) { Approval }
  owner = options.delete(:owner) { User }

  approval.send(:include, self)

  ActsAsApprovable.owner_class = owner
  ActsAsApprovable.owner_source = options.delete(:source)

  approval.send(:belongs_to, :owner, :class_name => owner.to_s, :foreign_key => :owner_id)
end

.included(base) ⇒ Object



33
34
35
36
# File 'lib/acts_as_approvable/ownership.rb', line 33

def self.included(base)
  base.send(:include, InstanceMethods)
  base.extend(ClassMethods)
end