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.25.0.1.b227 lib/acfs/model/validation.rb
acfs-0.25.0.1.b226 lib/acfs/model/validation.rb
acfs-0.25.0.1.b225 lib/acfs/model/validation.rb
acfs-0.25.0.1.b223 lib/acfs/model/validation.rb
acfs-0.25.0.1.b221 lib/acfs/model/validation.rb
acfs-0.25.0.1.b217 lib/acfs/model/validation.rb
acfs-0.25.0 lib/acfs/model/validation.rb
acfs-0.24.0.1.b216 lib/acfs/model/validation.rb
acfs-0.24.0.1.b214 lib/acfs/model/validation.rb
acfs-0.24.0.1.b212 lib/acfs/model/validation.rb
acfs-0.24.0.b210 lib/acfs/model/validation.rb
acfs-0.24.0 lib/acfs/model/validation.rb
acfs-0.23.2.b209 lib/acfs/model/validation.rb
acfs-0.23.2.b208 lib/acfs/model/validation.rb
acfs-0.23.2.b206 lib/acfs/model/validation.rb
acfs-0.23.2.b205 lib/acfs/model/validation.rb
acfs-0.23.2.b204 lib/acfs/model/validation.rb
acfs-0.23.2.b203 lib/acfs/model/validation.rb
acfs-0.23.2.b200 lib/acfs/model/validation.rb
acfs-0.23.2.b199 lib/acfs/model/validation.rb