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.10.0 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.9.0 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.8.5 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.8.4 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.8.3 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.8.2 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.8.1 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.8.0 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.23 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.22 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.21 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.20 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.19 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.18 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.17 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.16 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.15 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.14 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.13 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.7.12 lib/validators/scope_validator.rb