Module: Secretary::HasSecretary::ClassMethods

Defined in:
lib/secretary/has_secretary.rb

Instance Method Summary collapse

Instance Method Details

#has_secretary(options = {}) ⇒ Object

Declare that this class should be versioned.

Arguments

  • options (Hash) -

    • ‘on` (Array) - Array of Strings which specifies which

      attributes should be versioned.
      
    • ‘except` (Array) - Array of Strings which specifies which

      attributes should NOT be versioned.
      

Examples

has_secretary on: ["published_at", "user_id"]
has_secretary except: ["id", "created_at"]

Returns nothing



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/secretary/has_secretary.rb', line 33

def has_secretary(options={})
  @_has_secretary = true
  Secretary.versioned_models.push self.name

  self.versioned_attributes   = options[:on]     if options[:on]
  self.unversioned_attributes = options[:except] if options[:except]

  has_many :versions,
    :class_name   => "Secretary::Version",
    :as           => :versioned,
    :dependent    => :destroy

  attr_accessor :logged_user_id

  after_save :generate_version,
    :if => lambda { __versioned_changes.present? }

  after_save :reset_versioned_changes

  include InstanceMethodsOnActivation
end

#has_secretary?Boolean

Check if a class is versioned

Example

Story.has_secretary? # => true or false

Returns boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/secretary/has_secretary.rb', line 13

def has_secretary?
  !!@_has_secretary
end