Sha256: 17e50707cf93ebe2e7424848423983780d2ce9ec8e88c4c8604254329a4fdfed

Contents?: true

Size: 1.56 KB

Versions: 96

Compression:

Stored size: 1.56 KB

Contents

module Neo4j
  module Shared
    module Validations
      extend ActiveSupport::Concern
      include ActiveModel::Validations
      # Implements the ActiveModel::Validation hook method.
      # @see http://rubydoc.info/docs/rails/ActiveModel/Validations:read_attribute_for_validation
      def read_attribute_for_validation(key)
        respond_to?(key) ? send(key) : self[key]
      end

      # 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
      def save(options = {})
        result = perform_validations(options) ? super : false
        if !result
          Neo4j::Transaction.current.failure if Neo4j::Transaction.current
        end
        result
      end

      # @return [Boolean] true if valid
      def valid?(context = nil)
        context ||= (new_record? ? :create : :update)
        super(context)
        errors.empty?
      end

      private

      def perform_validations(options = {})
        perform_validation = case options
                             when Hash
                               options[:validate] != false
                             end

        if perform_validation
          valid?(options.is_a?(Hash) ? options[:context] : nil)
        else
          true
        end
      end
    end
  end
end

Version data entries

96 entries across 96 versions & 2 rubygems

Version Path
neo4j-5.2.7 lib/neo4j/shared/validations.rb
neo4j-5.2.6 lib/neo4j/shared/validations.rb
neo4j-5.2.5 lib/neo4j/shared/validations.rb
neo4j-5.2.3 lib/neo4j/shared/validations.rb
neo4j-5.2.2 lib/neo4j/shared/validations.rb
neo4j-5.2.1 lib/neo4j/shared/validations.rb
neo4j-5.2.0 lib/neo4j/shared/validations.rb
neo4j-5.1.5 lib/neo4j/shared/validations.rb
neo4j-5.1.4 lib/neo4j/shared/validations.rb
neo4j-5.1.3 lib/neo4j/shared/validations.rb
neo4j-5.1.2 lib/neo4j/shared/validations.rb
neo4j-5.1.1 lib/neo4j/shared/validations.rb
neo4j-5.1.0 lib/neo4j/shared/validations.rb
neo4j-5.1.0.rc.3 lib/neo4j/shared/validations.rb
neo4j-5.1.0.rc.2 lib/neo4j/shared/validations.rb
neo4j-5.1.0.rc.1 lib/neo4j/shared/validations.rb