Class: Attestor::Validations::Validator

Inherits:
Object
  • Object
show all
Includes:
Reporter
Defined in:
lib/attestor/validations/validator.rb

Direct Known Subclasses

Delegator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reporter

#validate

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

#blacklistObject (readonly)

Returns the value of attribute blacklist.



19
20
21
# File 'lib/attestor/validations/validator.rb', line 19

def blacklist
  @blacklist
end

#blockObject (readonly)

Returns the value of attribute block.



19
20
21
# File 'lib/attestor/validations/validator.rb', line 19

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/attestor/validations/validator.rb', line 19

def name
  @name
end

#whitelistObject (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

Returns:

  • (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