Sha256: 16231c9aae92dee5ca0dd8608babc4901801ffdeb36267037eb4e3749c3c416e

Contents?: true

Size: 484 Bytes

Versions: 27

Compression:

Stored size: 484 Bytes

Contents

class ScopeValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    id_method = :"#{attribute}_id"
    valid_collection = :"valid_#{attribute.to_s.pluralize}"

    if record.send(id_method).present?
      # Don't allow users to assign the IDs of other teams' or users' resources to this attribute.
      unless record.send(valid_collection).exists?(id: record.send(id_method))
        record.errors.add(id_method, :invalid)
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
bullet_train-scope_validator-1.7.11 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.10 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.9 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.3 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.2 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.1 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.0 lib/validators/scope_validator.rb