Sha256: e89d126e6df17ae1efa7d751c06f658aeb6e567877d11656a89122a95dba3d23

Contents?: true

Size: 451 Bytes

Versions: 14

Compression:

Stored size: 451 Bytes

Contents

module NinjaModel
  class Base
    include ActiveModel::Validations
    define_model_callbacks :validation
  end

  module Validation

    def save(options={})
      run_callbacks :validation do
        valid?(options.is_a?(Hash) ? options[:context] : nil) ? super : false
      end
    end

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ninja-model-0.7.3 lib/ninja_model/validation.rb
ninja-model-0.7.2 lib/ninja_model/validation.rb
ninja-model-0.7.1 lib/ninja_model/validation.rb
ninja-model-0.7.0 lib/ninja_model/validation.rb
ninja-model-0.6.2 lib/ninja_model/validation.rb
ninja-model-0.6.1 lib/ninja_model/validation.rb
ninja-model-0.6.0 lib/ninja_model/validation.rb
ninja-model-0.5.7 lib/ninja_model/validation.rb
ninja-model-0.5.6 lib/ninja_model/validation.rb
ninja-model-0.5.5 lib/ninja_model/validation.rb
ninja-model-0.5.4 lib/ninja_model/validation.rb
ninja-model-0.5.3 lib/ninja_model/validation.rb
ninja-model-0.5.2 lib/ninja_model/validation.rb
ninja-model-0.5.1 lib/ninja_model/validation.rb