Sha256: 731a2ca367258c6be577c7fb6a51c31b6cd45d11a2cd4eef8cefe02996180e9a

Contents?: true

Size: 496 Bytes

Versions: 111

Compression:

Stored size: 496 Bytes

Contents

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

    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

111 entries across 111 versions & 1 rubygems

Version Path
bullet_train-scope_validator-1.6.38 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.37 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.36 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.35 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.34 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.33 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.32 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.31 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.30 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.29 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.28 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.27 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.26 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.25 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.24 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.23 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.22 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.21 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.20 lib/validators/scope_validator.rb
bullet_train-scope_validator-1.6.19 lib/validators/scope_validator.rb