Extract version_class method for DRYness.
This commit is contained in:
parent
14e9bed0a6
commit
0cf5b2932c
|
@ -27,7 +27,7 @@ module PaperTrail
|
|||
attr_accessor :version
|
||||
|
||||
cattr_accessor :version_class_name
|
||||
self.version_class_name = options[:class_name] || "Version"
|
||||
self.version_class_name = options[:class_name] || 'Version'
|
||||
|
||||
cattr_accessor :ignore
|
||||
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
|
||||
|
@ -72,7 +72,7 @@ module PaperTrail
|
|||
|
||||
# Returns who put the object into its current state.
|
||||
def originator
|
||||
version_class_name.constantize.with_item_keys(self.class.name, id).last.try :whodunnit
|
||||
version_class.with_item_keys(self.class.name, id).last.try :whodunnit
|
||||
end
|
||||
|
||||
# Returns the object (not a Version) as it was at the given timestamp.
|
||||
|
@ -99,6 +99,10 @@ module PaperTrail
|
|||
|
||||
private
|
||||
|
||||
def version_class
|
||||
version_class_name.constantize
|
||||
end
|
||||
|
||||
def record_create
|
||||
if switched_on?
|
||||
versions.create merge_metadata(:event => 'create', :whodunnit => PaperTrail.whodunnit)
|
||||
|
@ -115,7 +119,7 @@ module PaperTrail
|
|||
|
||||
def record_destroy
|
||||
if switched_on? and not new_record?
|
||||
version_class_name.constantize.create merge_metadata(:item_id => self.id,
|
||||
version_class.create merge_metadata(:item_id => self.id,
|
||||
:item_type => self.class.name,
|
||||
:event => 'destroy',
|
||||
:object => object_to_string(item_before_change),
|
||||
|
|
Loading…
Reference in New Issue