module ZohoHub::WithValidations
Public Class Methods
included(base)
click to toggle source
# File lib/zoho_hub/with_validations.rb, line 8 def self.included(base) base.extend ClassMethods end
Public Instance Methods
add_error(field, message)
click to toggle source
# File lib/zoho_hub/with_validations.rb, line 51 def add_error(field, message) @errors << { field: field, message: message } end
errors()
click to toggle source
# File lib/zoho_hub/with_validations.rb, line 39 def errors @errors end
validate!()
click to toggle source
# File lib/zoho_hub/with_validations.rb, line 31 def validate! @errors = [] self.class.validations.each { |validation| validate_field!(validation) } @errors end
validate_field!(params = {})
click to toggle source
# File lib/zoho_hub/with_validations.rb, line 43 def validate_field!(params = {}) options = params.dup validate = options.delete(:validate) validator = Module.const_get("Validations::Validate#{validate.downcase.capitalize}") validator.new(self, options[:field]).validate(options) end