Class: HashValidator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_validator/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, validations) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
# File 'lib/hash_validator/base.rb', line 5

def initialize(hash, validations)
  self.errors      = {}
  self.hash        = hash
  self.validations = validations

  validate
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



2
3
4
# File 'lib/hash_validator/base.rb', line 2

def errors
  @errors
end

#hashObject

Returns the value of attribute hash.



2
3
4
# File 'lib/hash_validator/base.rb', line 2

def hash
  @hash
end

#validationsObject

Returns the value of attribute validations.



2
3
4
# File 'lib/hash_validator/base.rb', line 2

def validations
  @validations
end

Class Method Details

.strict?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/hash_validator/base.rb', line 22

def self.strict?
  @strict
end

.validate(hash, validations, strict = false) ⇒ Object



17
18
19
20
# File 'lib/hash_validator/base.rb', line 17

def self.validate(hash, validations, strict = false)
  @strict = strict
  new(hash, validations)
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/hash_validator/base.rb', line 13

def valid?
  errors.empty?
end