Class: Attestor::Validations::Validator
- Inherits:
-
Object
- Object
- Attestor::Validations::Validator
- Includes:
- Reporter
- Defined in:
- lib/attestor/validations/validator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#blacklist ⇒ Object
readonly
Returns the value of attribute blacklist.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#whitelist ⇒ Object
readonly
Returns the value of attribute whitelist.
Instance Method Summary collapse
-
#initialize(name = :invalid, except: nil, only: nil, &block) ⇒ Validator
constructor
A new instance of Validator.
- #used_in_context?(context) ⇒ Boolean
- #validate!(object) ⇒ Object
Methods included from Reporter
Constructor Details
#initialize(name = :invalid, except: nil, only: nil, &block) ⇒ Validator
Returns a new instance of Validator.
11 12 13 14 15 16 17 |
# File 'lib/attestor/validations/validator.rb', line 11 def initialize(name = :invalid, except: nil, only: nil, &block) @name = name.to_sym @whitelist = normalize(only) @blacklist = normalize(except) @block = block freeze end |
Instance Attribute Details
#blacklist ⇒ Object (readonly)
Returns the value of attribute blacklist.
19 20 21 |
# File 'lib/attestor/validations/validator.rb', line 19 def blacklist @blacklist end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
19 20 21 |
# File 'lib/attestor/validations/validator.rb', line 19 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/attestor/validations/validator.rb', line 19 def name @name end |
#whitelist ⇒ Object (readonly)
Returns the value of attribute whitelist.
19 20 21 |
# File 'lib/attestor/validations/validator.rb', line 19 def whitelist @whitelist end |
Instance Method Details
#used_in_context?(context) ⇒ Boolean
21 22 23 24 |
# File 'lib/attestor/validations/validator.rb', line 21 def used_in_context?(context) symbol = context.to_sym whitelisted?(symbol) && !blacklisted?(symbol) end |
#validate!(object) ⇒ Object
26 27 28 |
# File 'lib/attestor/validations/validator.rb', line 26 def validate!(object) block ? object.instance_eval(&block) : object.__send__(name) end |