diff --git a/lib/acts_as_revisable/acts/common.rb b/lib/acts_as_revisable/acts/common.rb index d664cd0..ecb4930 100644 --- a/lib/acts_as_revisable/acts/common.rb +++ b/lib/acts_as_revisable/acts/common.rb @@ -156,7 +156,7 @@ def #{a.to_s}_with_open_scope(*args, &block) assoc = self.class.reflect_on_association(#{a.inspect}) models = [self.class] - if assoc.macro == :has_many + if [:has_many, :has_one].member? assoc.macro models << (assoc.options[:class_name] ? assoc.options[:class_name] : #{a.inspect}.to_s.singularize.camelize).constantize end diff --git a/lib/acts_as_revisable/acts/revisable.rb b/lib/acts_as_revisable/acts/revisable.rb index 2905e53..e38b34c 100644 --- a/lib/acts_as_revisable/acts/revisable.rb +++ b/lib/acts_as_revisable/acts/revisable.rb @@ -341,6 +341,10 @@ def current_revision self end + def for_revision + + end + module ClassMethods # acts_as_revisable's override for with_scope that allows for # including revisions in the scope. diff --git a/lib/acts_as_revisable/acts/revision.rb b/lib/acts_as_revisable/acts/revision.rb index d42291c..838434b 100644 --- a/lib/acts_as_revisable/acts/revision.rb +++ b/lib/acts_as_revisable/acts/revision.rb @@ -76,7 +76,11 @@ def revision_setup #:nodoc: self[:revisable_type] = current_revision[:type] self[:revisable_number] = (self.class.maximum(:revisable_number, :conditions => {:revisable_original_id => self[:revisable_original_id]}) || 0) + 1 end - + + def from_revisable + + end + module ClassMethods # Returns the +revisable_class_name+ as configured in # +acts_as_revisable+. diff --git a/lib/acts_as_revisable/acts/scoped_model.rb b/lib/acts_as_revisable/acts/scoped_model.rb index 5dad050..6d3332f 100644 --- a/lib/acts_as_revisable/acts/scoped_model.rb +++ b/lib/acts_as_revisable/acts/scoped_model.rb @@ -8,7 +8,7 @@ module ClassMethods SCOPED_METHODS = %w(construct_calculation_sql construct_finder_sql update_all delete_all destroy_all).freeze def call_method_with_static_scope(meth, args) - return send(meth, *args) unless self.scoped_model_enabled + return send(meth, *args) unless self.scoped_model_enabled? with_scope(self.scoped_model_static_scope) do send(meth, *args) @@ -36,14 +36,38 @@ def without_model_scope rv end + def disable_model_scope! + self.scoped_model_disable_count += 1 + end + + def enable_model_scope! + self.scoped_model_disable_count -= 1 + end + + def scoped_model_enabled? + self.scoped_model_disable_count == 0 + end + + def scoped_model_enabled + self.scoped_model_enabled? + end + + def scoped_model_enabled=(value) + if value == false + disable_model_scope! + else + enable_model_scope! + end + end + def acts_as_scoped_model(*args) class << self - attr_accessor :scoped_model_static_scope, :scoped_model_enabled + attr_accessor :scoped_model_static_scope, :scoped_model_disable_count SCOPED_METHODS.each do |m| alias_method_chain m.to_sym, :static_scope end end - self.scoped_model_enabled = true + self.scoped_model_disable_count = 0 self.scoped_model_static_scope = args.extract_options! end end