Class: CanValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/can_validator.rb,
lib/can_validator/engine.rb,
lib/can_validator/version.rb

Defined Under Namespace

Classes: Engine

Constant Summary collapse

RESERVED_OPTIONS =
[:allow_nil, :allow_blank, :message, :on, :if, :unless]
VERSION =
'0.0.2'

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
# File 'lib/can_validator.rb', line 4

def validate_each(record, attribute, value)
  if !value.respond_to?(:can?) || !has_permission?(record, value)
    record.errors.add(attribute, options[:message] || :permission_denied)
  end
end