module ActiveGraph::Shared::Validations
Public Instance Methods
read_attribute_for_validation(key)
click to toggle source
Implements the ActiveModel::Validation hook method. @see rubydoc.info/docs/rails/ActiveModel/Validations:read_attribute_for_validation
# File lib/active_graph/shared/validations.rb 8 def read_attribute_for_validation(key) 9 respond_to?(key) ? send(key) : self[key] 10 end
save(options = {})
click to toggle source
The validation process on save can be skipped by passing false. The regular Model#save method is replaced with this when the validations module is mixed in, which it is by default. @param [Hash] options the options to create a message with. @option options [true, false] :validate if false no validation will take place @return [Boolean] true if it saved it successfully
Calls superclass method
# File lib/active_graph/shared/validations.rb 17 def save(options = {}) 18 perform_validations(options) ? super : false 19 end
valid?(context = nil)
click to toggle source
@return [Boolean] true if valid
Calls superclass method
# File lib/active_graph/shared/validations.rb 22 def valid?(context = nil) 23 context ||= (new_record? ? :create : :update) 24 super(context) 25 errors.empty? 26 end
Private Instance Methods
perform_validations(options = {})
click to toggle source
# File lib/active_graph/shared/validations.rb 30 def perform_validations(options = {}) 31 perform_validation = case options 32 when Hash 33 options[:validate] != false 34 end 35 36 if perform_validation 37 valid?(options.is_a?(Hash) ? options[:context] : nil) 38 else 39 true 40 end 41 end