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.

Constant Summary collapse

E_PT_AT_REMOVED =
<<-EOS.squish
  Association Tracking for PaperTrail has been extracted to a seperate gem.
  To use it, please add `paper_trail-association_tracking` to your Gemfile.
  If you don't use it (most people don't, that's the default) and you set
  `track_associations = false` somewhere (probably a rails initializer) you
  can remove that line now.
EOS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

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.
  @serializer = PaperTrail::Serializers::YAML
end

Instance Attribute Details

#association_reify_error_behaviourObject

Returns the value of attribute association_reify_error_behaviour.



20
21
22
# File 'lib/paper_trail/config.rb', line 20

def association_reify_error_behaviour
  @association_reify_error_behaviour
end

#object_changes_adapterObject

Returns the value of attribute object_changes_adapter.



20
21
22
# File 'lib/paper_trail/config.rb', line 20

def object_changes_adapter
  @object_changes_adapter
end

#serializerObject

Returns the value of attribute serializer.



20
21
22
# File 'lib/paper_trail/config.rb', line 20

def serializer
  @serializer
end

#version_limitObject

Returns the value of attribute version_limit.



20
21
22
# File 'lib/paper_trail/config.rb', line 20

def version_limit
  @version_limit
end

Instance Method Details

#enabledObject

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



37
38
39
# File 'lib/paper_trail/config.rb', line 37

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

#enabled=(enable) ⇒ Object



41
42
43
# File 'lib/paper_trail/config.rb', line 41

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

#track_associations=(value) ⇒ Object

In PT 10, the paper_trail-association_tracking gem was changed from a runtime dependency to a development dependency. We raise an error about this for the people who don’t read changelogs.

We raise a generic RuntimeError instead of a specific PT error class because there is no known use case where someone would want to rescue this. If we think of such a use case in the future we can revisit this decision.

own implementation.



56
57
58
59
60
61
62
# File 'lib/paper_trail/config.rb', line 56

def track_associations=(value)
  if value
    raise E_PT_AT_REMOVED
  else
    ::Kernel.warn(E_PT_AT_REMOVED)
  end
end

#track_associations?Boolean

own implementation.

Returns:

  • (Boolean)

Raises:



66
67
68
# File 'lib/paper_trail/config.rb', line 66

def track_associations?
  raise E_PT_AT_REMOVED
end