Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9172

Show
Ignore:
Timestamp:
03/31/08 23:45:48 (4 months ago)
Author:
david
Message:

Deprecate some more legacy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activemodel/lib/active_model/validations.rb

    r9171 r9172  
    623623    end 
    624624 
    625     # The validation process on save can be skipped by passing false. The regular Base#save method is 
    626     # replaced with this when the validations module is mixed in, which it is by default. 
    627     def save_with_validation(perform_validation = true) 
    628       if perform_validation && valid? || !perform_validation 
    629         save_without_validation 
    630       else 
    631         false 
    632       end 
    633     end 
    634  
    635     # Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false 
    636     # if the record is not valid. 
    637     def save_with_validation! 
    638       if valid? 
    639         save_without_validation! 
    640       else 
    641         raise RecordInvalid.new(self) 
    642       end 
    643     end 
    644  
    645     # Updates a single attribute and saves the record without going through the normal validation procedure. 
    646     # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method 
    647     # in Base is replaced with this when the validations module is mixed in, which it is by default. 
    648     def update_attribute_with_validation_skipping(name, value) 
    649       send(name.to_s + '=', value) 
    650       save(false) 
    651     end 
    652625 
    653626    # Runs validate and validate_on_create or validate_on_update and returns true if no errors were added otherwise false. 
     
    656629 
    657630      run_callbacks(:validate) 
    658       validate 
     631       
     632      if responds_to?(:validate) 
     633        ActiveSupport::Deprecations.warn "Base#validate has been deprecated, please use Base.validate :method instead" 
     634        validate 
     635      end 
    659636 
    660637      if new_record? 
    661638        run_callbacks(:validate_on_create) 
    662         validate_on_create 
     639 
     640        if responds_to?(:validate_on_create) 
     641          ActiveSupport::Deprecations.warn( 
     642            "Base#validate_on_create has been deprecated, please use Base.validate :method, :on => :create instead") 
     643          validate_on_create 
     644        end 
    663645      else 
    664646        run_callbacks(:validate_on_update) 
    665         validate_on_update 
     647 
     648        if responds_to?(:validate_on_update) 
     649          ActiveSupport::Deprecations.warn( 
     650            "Base#validate_on_update has been deprecated, please use Base.validate :method, :on => :update instead") 
     651          validate_on_update 
     652        end 
    666653      end 
    667654 
     
    671658    # Returns the Errors object that holds all information about attribute error messages. 
    672659    def errors 
    673       @errors ||= Errors.new(self) 
     660      @errors ||= Errors.new 
    674661    end 
    675  
    676     protected 
    677       # Overwrite this method for validation checks on all saves and use Errors.add(field, msg) for invalid attributes. 
    678       def validate #:doc: 
    679       end 
    680  
    681       # Overwrite this method for validation checks used only on creation. 
    682       def validate_on_create #:doc: 
    683       end 
    684  
    685       # Overwrite this method for validation checks used only on updates. 
    686       def validate_on_update # :doc: 
    687       end 
    688662  end 
    689663end