Class: Burner::Modeling::Validations::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/burner/modeling/validations/base.rb

Overview

Common logic shared among all Validation subclasses. This class is an abstract class, make sure to implement:

  • #valid?(object, resolver)

  • #default_message

Direct Known Subclasses

Blank

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, message: '') ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/burner/modeling/validations/base.rb', line 22

def initialize(key:, message: '')
  raise ArgumentError, 'key is required' if key.to_s.empty?

  @key     = key.to_s
  @message = message.to_s
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



20
21
22
# File 'lib/burner/modeling/validations/base.rb', line 20

def key
  @key
end

Instance Method Details

#messageObject



29
30
31
# File 'lib/burner/modeling/validations/base.rb', line 29

def message
  @message.to_s.empty? ? "#{key} #{default_message}" : @message.to_s
end