2016-03-05 17:07:32 -05:00
|
|
|
require "singleton"
|
|
|
|
require "paper_trail/serializers/yaml"
|
2012-10-30 16:01:13 -04:00
|
|
|
|
2010-03-19 11:21:07 -04:00
|
|
|
module PaperTrail
|
|
|
|
class Config
|
|
|
|
include Singleton
|
2015-05-26 15:39:09 -04:00
|
|
|
attr_accessor :timestamp_field, :serializer, :version_limit
|
2015-03-25 19:17:22 -04:00
|
|
|
attr_writer :track_associations
|
2012-07-03 23:22:52 -04:00
|
|
|
|
2010-03-19 11:21:07 -04:00
|
|
|
def initialize
|
2016-03-03 18:16:47 -05:00
|
|
|
# Variables which affect all threads, whose access is synchronized.
|
|
|
|
@mutex = Mutex.new
|
|
|
|
@enabled = true
|
|
|
|
|
|
|
|
# Variables which affect all threads, whose access is *not* synchronized.
|
2012-02-01 14:47:06 -05:00
|
|
|
@timestamp_field = :created_at
|
2013-10-17 22:05:24 -04:00
|
|
|
@serializer = PaperTrail::Serializers::YAML
|
2015-12-09 10:58:27 -05:00
|
|
|
end
|
2014-12-29 14:38:32 -05:00
|
|
|
|
2015-12-09 10:58:27 -05:00
|
|
|
def serialized_attributes
|
|
|
|
ActiveSupport::Deprecation.warn(
|
2015-12-22 11:32:50 -05:00
|
|
|
"PaperTrail.config.serialized_attributes is deprecated without " +
|
|
|
|
"replacement and always returns false."
|
2015-12-09 10:58:27 -05:00
|
|
|
)
|
2015-12-22 11:32:50 -05:00
|
|
|
false
|
2014-12-29 14:38:32 -05:00
|
|
|
end
|
|
|
|
|
2015-12-09 10:58:27 -05:00
|
|
|
def serialized_attributes=(_)
|
|
|
|
ActiveSupport::Deprecation.warn(
|
2015-12-22 11:32:50 -05:00
|
|
|
"PaperTrail.config.serialized_attributes= is deprecated without " +
|
|
|
|
"replacement and no longer has any effect."
|
2015-12-09 10:58:27 -05:00
|
|
|
)
|
2010-03-19 11:21:07 -04:00
|
|
|
end
|
2015-03-25 19:17:22 -04:00
|
|
|
|
|
|
|
def track_associations
|
2015-10-31 22:58:54 -04:00
|
|
|
@track_associations.nil? ?
|
|
|
|
PaperTrail::VersionAssociation.table_exists? :
|
|
|
|
@track_associations
|
2015-03-25 19:17:22 -04:00
|
|
|
end
|
|
|
|
alias_method :track_associations?, :track_associations
|
2015-07-12 23:43:25 -04:00
|
|
|
|
2015-12-07 12:12:02 -05:00
|
|
|
# Indicates whether PaperTrail is on or off. Default: true.
|
2015-05-26 15:39:09 -04:00
|
|
|
def enabled
|
2016-03-03 18:16:47 -05:00
|
|
|
@mutex.synchronize { !!@enabled }
|
2015-05-26 15:39:09 -04:00
|
|
|
end
|
2015-07-12 23:43:25 -04:00
|
|
|
|
2016-03-13 19:55:12 -04:00
|
|
|
def enabled=(enable)
|
2016-03-03 18:16:47 -05:00
|
|
|
@mutex.synchronize { @enabled = enable }
|
2015-05-26 15:39:09 -04:00
|
|
|
end
|
2010-03-19 11:21:07 -04:00
|
|
|
end
|
|
|
|
end
|