Sha256: 9c75b07f8b0900573a14c5d7eae6b7e12a5fc675d28d82a721e4706716b0bb06

Contents?: true

Size: 842 Bytes

Versions: 20

Compression:

Stored size: 842 Bytes

Contents

# encoding: utf-8
module Dynamoid
  
  # Provide ActiveModel validations to Dynamoid documents.
  module Validations
    extend ActiveSupport::Concern

    include ActiveModel::Validations
    include ActiveModel::Validations::Callbacks

    # Override save to provide validation support.
    #
    # @since 0.2.0
    def save(options = {})
      options.reverse_merge!(:validate => true)
      return false if options[:validate] and (not valid?)
      super
    end

    # Is this object valid?
    #
    # @since 0.2.0
    def valid?(context = nil)
      context ||= (new_record? ? :create : :update)
      super(context)
    end

    # Raise an error unless this object is valid.
    #
    # @since 0.2.0
    def save!
      raise Dynamoid::Errors::DocumentNotValid.new(self) unless valid?
      save(:validate => false)
    end
  end
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
dynamoid-edge-1.1.1 lib/dynamoid/validations.rb
dynamoid-edge-1.1.0 lib/dynamoid/validations.rb
dynamoid-1.1.0 lib/dynamoid/validations.rb
dynamoid-1.0.0 lib/dynamoid/validations.rb
dynamoid-moda-0.7.2 lib/dynamoid/validations.rb
dynamoid-moda-0.7.1 lib/dynamoid/validations.rb
dynamoid-0.7.1 lib/dynamoid/validations.rb
dynamoid-0.7.0 lib/dynamoid/validations.rb
dynamoid-0.6.1 lib/dynamoid/validations.rb
dynamoid-0.6.0 lib/dynamoid/validations.rb
adept_dynamoid-0.6.0 lib/dynamoid/validations.rb
adept_dynamoid-0.5.0.8 lib/dynamoid/validations.rb
adept_dynamoid-0.5.0.7 lib/dynamoid/validations.rb
adept_dynamoid-0.5.0.6 lib/dynamoid/validations.rb
dynamoid-0.5.0 lib/dynamoid/validations.rb
dynamoid-0.4.1 lib/dynamoid/validations.rb
dynamoid-0.4.0 lib/dynamoid/validations.rb
dynamoid-0.3.2 lib/dynamoid/validations.rb
dynamoid-0.3.1 lib/dynamoid/validations.rb
dynamoid-0.3.0 lib/dynamoid/validations.rb