Sha256: 33a17a1df22c9ac263b9d24221d64391648cc8c3e95c63a3abe00319897ce071

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

module Neo4j
  module Rails
    module Validations
      include ActiveModel::Validations

      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.
      def save(options={})
        perform_validations(options) ? super : false
      end

      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

10 entries across 10 versions & 1 rubygems

Version Path
neo4j-1.2.1-java lib/neo4j/rails/validations.rb
neo4j-1.2.0-java lib/neo4j/rails/validations.rb
neo4j-1.1.4-java lib/neo4j/rails/validations.rb
neo4j-1.1.3-java lib/neo4j/rails/validations.rb
neo4j-1.1.2-java lib/neo4j/rails/validations.rb
neo4j-1.1.1-java lib/neo4j/rails/validations.rb
neo4j-1.1.0-java lib/neo4j/rails/validations.rb
neo4j-1.1.0.beta.3-java lib/neo4j/rails/validations.rb
neo4j-1.1.0.beta.2-java lib/neo4j/rails/validations.rb
neo4j-1.1.0.beta.1-java lib/neo4j/rails/validations.rb