Class: Attestor::Validations::Validator Private
- Inherits:
-
Object
- Object
- Attestor::Validations::Validator
- Defined in:
- lib/attestor/validations/validator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Describe a validator for class instances
Direct Known Subclasses
Class Attribute Summary collapse
-
.name ⇒ Symbol
readonly
private
The name of the item.
Class Method Summary collapse
-
.==(other) ⇒ Boolean
private
Compares an item to another one.
- .initialize(name, except: nil, only: nil, &block) ⇒ Object private
-
.new(name, except: [], only: []) ⇒ Attestor::Validations::Validator
Creates a named item with blacklist or whitelist of contexts.
-
.used_in_context?(context) ⇒ Boolean
private
Checks if the item should be used in given context.
-
.validate(object) ⇒ undefined
private
Validates given object.
Class Attribute Details
.name ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The name of the item
42 43 44 |
# File 'lib/attestor/validations/validator.rb', line 42 def name @name end |
Class Method Details
.==(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compares an item to another one
49 50 51 |
# File 'lib/attestor/validations/validator.rb', line 49 def ==(other) other.instance_of?(self.class) ? id.equal?(other.id) : false end |
.initialize(name, except: nil, only: nil, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 34 35 36 |
# File 'lib/attestor/validations/validator.rb', line 29 def initialize(name, except: nil, only: nil, &block) @name = name.to_sym @whitelist = normalize(only) @blacklist = normalize(except) @block = block generate_id freeze end |
.new(name, except: [], only: []) ⇒ Attestor::Validations::Validator
Creates a named item with blacklist or whitelist of contexts
|
|
# File 'lib/attestor/validations/validator.rb', line 18
|
.used_in_context?(context) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if the item should be used in given context
58 59 60 61 |
# File 'lib/attestor/validations/validator.rb', line 58 def used_in_context?(context) symbol = context.to_sym whitelisted?(symbol) && !blacklisted?(symbol) end |
.validate(object) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates given object
71 72 73 |
# File 'lib/attestor/validations/validator.rb', line 71 def validate(object) block ? object.instance_eval(&block) : object.__send__(name) end |