Sha256: 1f6fbdaae1867629e0b80dd1ab82addda72375bc619693b4547bb9031236cdfe

Contents?: true

Size: 605 Bytes

Versions: 89

Compression:

Stored size: 605 Bytes

Contents

module Acfs::Model

  #
  #
  module Validation

    def valid?(*args)
      super
      remote_errors.each { |f, e| errors.add f, e }
      errors.empty?
    end

    def remote_errors
      @remote_errors ||= ActiveModel::Errors.new self
    end

    def remote_errors=(errors)
      (errors || []).each do |field, errors|
        self.errors.set field.to_sym, errors
        self.remote_errors.set field.to_sym, errors
      end
    end

    def save!(*_)
      raise ::Acfs::InvalidResource.new resource: self, errors: errors.to_a unless valid? (new? ? :create : :save)

      super
    end
  end
end

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
acfs-0.42.0 lib/acfs/model/validation.rb
acfs-0.41.1 lib/acfs/model/validation.rb
acfs-0.41.1.beta1 lib/acfs/model/validation.rb
acfs-0.41.0 lib/acfs/model/validation.rb
acfs-0.40.1.rc1 lib/acfs/model/validation.rb
acfs-0.40.0 lib/acfs/model/validation.rb
acfs-0.39.1 lib/acfs/model/validation.rb
acfs-0.39.0 lib/acfs/model/validation.rb
acfs-0.38.0 lib/acfs/model/validation.rb
acfs-0.37.0.1.b295 lib/acfs/model/validation.rb
acfs-0.37.0 lib/acfs/model/validation.rb
acfs-0.36.0.1.b293 lib/acfs/model/validation.rb
acfs-0.36.0 lib/acfs/model/validation.rb
acfs-0.35.0.1.b291 lib/acfs/model/validation.rb
acfs-0.35.0 lib/acfs/model/validation.rb
acfs-0.34.1.1.b289 lib/acfs/model/validation.rb
acfs-0.34.1 lib/acfs/model/validation.rb
acfs-0.34.0.1.b288 lib/acfs/model/validation.rb
acfs-0.34.0.1.b287 lib/acfs/model/validation.rb
acfs-0.34.0.1.b286 lib/acfs/model/validation.rb