Class: Related::CheckRedisUniqueness

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/related/validations/check_redis_uniqueness.rb

Instance Method Summary collapse

Instance Method Details

#validate(entity) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/related/validations/check_redis_uniqueness.rb', line 3

def validate(entity)
  internal_id = entity.instance_variable_get(:@_internal_id)

  if Related.redis.exists(internal_id)
    entity.errors[:id] << "#{internal_id.inspect} already exists."
  end
end