Class: PaperTrail::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/paper_trail/config.rb

Overview

Global configuration affecting all threads. Some thread-specific configuration can be found in paper_trail.rb, others in controller.rb.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
# File 'lib/paper_trail/config.rb', line 12

def initialize
  # Variables which affect all threads, whose access is synchronized.
  @mutex = Mutex.new
  @enabled = true

  # Variables which affect all threads, whose access is *not* synchronized.
  @timestamp_field = :created_at
  @serializer = PaperTrail::Serializers::YAML
end

Instance Attribute Details

#serializerObject

Returns the value of attribute serializer.



9
10
11
# File 'lib/paper_trail/config.rb', line 9

def serializer
  @serializer
end

#timestamp_fieldObject

Returns the value of attribute timestamp_field.



9
10
11
# File 'lib/paper_trail/config.rb', line 9

def timestamp_field
  @timestamp_field
end

#track_associations=(value) ⇒ Object (writeonly)

Sets the attribute track_associations

Parameters:

  • value

    the value to set the attribute track_associations to.



10
11
12
# File 'lib/paper_trail/config.rb', line 10

def track_associations=(value)
  @track_associations = value
end

#version_limitObject

Returns the value of attribute version_limit.



9
10
11
# File 'lib/paper_trail/config.rb', line 9

def version_limit
  @version_limit
end

Instance Method Details

#enabledObject

Indicates whether PaperTrail is on or off. Default: true.



56
57
58
# File 'lib/paper_trail/config.rb', line 56

def enabled
  @mutex.synchronize { !!@enabled }
end

#enabled=(enable) ⇒ Object



60
61
62
# File 'lib/paper_trail/config.rb', line 60

def enabled=(enable)
  @mutex.synchronize { @enabled = enable }
end

#serialized_attributesObject



22
23
24
25
26
27
28
# File 'lib/paper_trail/config.rb', line 22

def serialized_attributes
  ActiveSupport::Deprecation.warn(
    "PaperTrail.config.serialized_attributes is deprecated without " +
      "replacement and always returns false."
  )
  false
end

#serialized_attributes=(_) ⇒ Object



30
31
32
33
34
35
# File 'lib/paper_trail/config.rb', line 30

def serialized_attributes=(_)
  ActiveSupport::Deprecation.warn(
    "PaperTrail.config.serialized_attributes= is deprecated without " +
      "replacement and no longer has any effect."
  )
end

#track_associations?Boolean

Previously, we checked PaperTrail::VersionAssociation.table_exists? here, but that proved to be problematic in situations when the database connection had not been established, or when the database does not exist yet (as with ‘rake db:create`).

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/paper_trail/config.rb', line 41

def track_associations?
  if @track_associations.nil?
    ActiveSupport::Deprecation.warn <<-EOS.strip_heredoc.gsub(/\s+/, " ")
      PaperTrail.track_associations has not been set. As of PaperTrail 5, it
      defaults to false. Tracking associations is an experimental feature so
      we recommend setting PaperTrail.config.track_associations = false in
      your config/initializers/paper_trail.rb
    EOS
    false
  else
    @track_associations
  end
end