module Neo4j::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/neo4j/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/neo4j/shared/validations.rb
17 def save(options = {})
18   result = perform_validations(options) ? super : false
19   if !result
20     Neo4j::Transaction.current.failure if Neo4j::Transaction.current
21   end
22   result
23 end
valid?(context = nil) click to toggle source

@return [Boolean] true if valid

Calls superclass method
   # File lib/neo4j/shared/validations.rb
26 def valid?(context = nil)
27   context ||= (new_record? ? :create : :update)
28   super(context)
29   errors.empty?
30 end

Private Instance Methods

perform_validations(options = {}) click to toggle source
   # File lib/neo4j/shared/validations.rb
34 def perform_validations(options = {})
35   perform_validation = case options
36                        when Hash
37                          options[:validate] != false
38                        end
39 
40   if perform_validation
41     valid?(options.is_a?(Hash) ? options[:context] : nil)
42   else
43     true
44   end
45 end