Factlink / pavlov

Provides a Command/Query/Interactor framework.
MIT License
22 stars 4 forks source link

Validation helpers via errors object #52

Open marten opened 10 years ago

marten commented 10 years ago

The actual API is also up for debate, so feel free to have better ideas than just using ActiveModel::Errors. The new README proposes:

  def validate
    errors.add(:id, "can't contain spaces") if id.include?(" ")
  end
markijbema commented 10 years ago

I like this, especially since we could actually make the validations compatible:

    def validate_integer_string param_name, param
      return if param.is_a?(String) && /\A\d+\Z/.match(param)

      errors.add param_name.to_s,  "should be an integer string."
    end

That way we could decouple this functionality introduction from removing calls to validation helpers, allowing us to first upgrade, and then one by one remove old validations.