lib/simple_model/base.rb in simple_model-1.4.1 vs lib/simple_model/base.rb in simple_model-1.4.2

- old
+ new

@@ -81,23 +81,31 @@ define_model_callbacks :save, :update, :create, :destroy class << self + def after_any(meth=nil) + @after_any = meth if meth + @after_any + end + # Defines the model action's instance methods and applied defaults. For every # action defined, we also define that actions ! method which raises exceptions # when the action fails. def define_model_action(methods,action,default_options={:validate => true}) default_options.merge!(methods.extract_options!) actions = [action,"#{action}!".to_sym] actions.each do |a| define_method(a) do |opts = {}| + rslt = nil options = default_options.merge(opts) options[:raise_exception] = a.to_s.match(/\!$/) run_callbacks(action) do - run_model_action(methods,options) + rslt = run_model_action(methods,options) end + run_after_any + rslt end end end def save(*methods) @@ -123,9 +131,13 @@ has_boolean :new_record, :default => true has_attribute :id # may not be an integer alias :saved? :persisted? private + + def run_after_any + self.send(self.class.after_any) if self.class.after_any + end # Skeleton for action instance methods def run_model_action(methods,options) completed = true if (!options[:validate] || (options[:validation_methods] && valid_using_other?(options[:validation_methods])) || self.valid?)