Sha256: f34465aa0447050443c6a1d5f45fcb0d263b2ec6f879123ba78a0160c3619653

Contents?: true

Size: 599 Bytes

Versions: 5

Compression:

Stored size: 599 Bytes

Contents

module NinjaModel

  module Validation
    extend ActiveSupport::Concern

    included do
      include ActiveModel::Validations
      define_model_callbacks :validation
    end

    def save(options={})
      perform_validations(options) ? super : false
    end

    def valid?(context = nil)
      context ||= (persisted? ? :update : :create)
      output = super(context)
      errors.empty? && output
    end

    protected

    def perform_validations(options)
      perform_validation = options[:validate] != false
      perform_validation ? valid?(options[:context]) : true
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ninja-model-0.9.2 lib/ninja_model/validation.rb
ninja-model-0.9.1 lib/ninja_model/validation.rb
ninja-model-0.9.0 lib/ninja_model/validation.rb
ninja-model-0.8.1 lib/ninja_model/validation.rb
ninja-model-0.8.0 lib/ninja_model/validation.rb