Class: YaKassa::V3::Validators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ya_kassa/v3/validators/base.rb

Direct Known Subclasses

FloatOrNil, IsA, IsABoolean, Present

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, params = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
# File 'lib/ya_kassa/v3/validators/base.rb', line 7

def initialize(name, value, params = {})
  @name = name
  @value = value
  @params = params
  @error = nil
  @is_validated = false
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



5
6
7
# File 'lib/ya_kassa/v3/validators/base.rb', line 5

def error
  @error
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/ya_kassa/v3/validators/base.rb', line 5

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/ya_kassa/v3/validators/base.rb', line 5

def value
  @value
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/ya_kassa/v3/validators/base.rb', line 21

def valid?
  unless @is_validated
    msg = "#{self.class.name}. Need to run #validate method before call #valid?"
    Rails.logger.info(msg)
    return nil
  end
  @error.blank?
end

#validateObject



15
16
17
18
19
# File 'lib/ya_kassa/v3/validators/base.rb', line 15

def validate
  @error = error_msg unless condition
  @is_validated = true
  nil
end