[#708] Using instance var to store journal class name

this way journal classes are only created for classes with
calls to acts_as_journalized. You may now subclass journaled models to extend them with helper methods in plugins w/o interfering with aaj.
This commit is contained in:
Gregor Schmidt 2011-07-26 17:34:16 +02:00
parent 0462fa973b
commit e2938d26f3
2 changed files with 13 additions and 6 deletions

View File

@ -32,6 +32,10 @@ module Redmine
end
module ClassMethods
attr_writer :journal_class_name
def journal_class_name
defined?(@journal_class_name) ? @journal_class_name : superclass.journal_class_name
end
def plural_name
self.name.underscore.pluralize
@ -55,6 +59,8 @@ module Redmine
def acts_as_journalized(options = {}, &block)
activity_hash, event_hash, journal_hash = split_option_hashes(options)
self.journal_class_name = journal_hash.delete(:class_name) || "#{name.gsub("::", "_")}Journal"
acts_as_activity(activity_hash)
return if journaled?
@ -77,13 +83,13 @@ module Redmine
(journal_hash[:except] ||= []) << self.primary_key << inheritance_column <<
:updated_on << :updated_at << :lock_version << :lft << :rgt
prepare_journaled_options(journal_hash)
has_many :journals, journal_hash.merge({:class_name => journal_class.name,
:foreign_key => "journaled_id"}), &block
has_many :journals, journal_hash, &block
end
def journal_class
journal_class_name = "#{name.gsub("::", "_")}Journal"
if Object.const_defined?(journal_class_name)
Object.const_get(journal_class_name)
else

View File

@ -63,11 +63,12 @@ module Redmine::Acts::Journalized
options.symbolize_keys!
options.reverse_merge!(Configuration.options)
options.reverse_merge!(
:class_name => 'Journal',
:dependent => :delete_all
:class_name => journal_class_name,
:dependent => :delete_all,
:foreign_key => "journaled_id"
)
options.reverse_merge!(
:order => "#{options[:class_name].constantize.table_name}.version ASC"
:order => "#{journal_class.table_name}.version ASC"
)
class_inheritable_accessor :vestal_journals_options