Class: Sevgi::ValidationError

Inherits:
Error
  • Object
show all
Defined in:
lib/sevgi/standard/errors.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, args = []) ⇒ ValidationError

Returns a new instance of ValidationError.



5
6
7
8
9
10
# File 'lib/sevgi/standard/errors.rb', line 5

def initialize(context, args = [])
  @context = context
  @args = Array(args)

  super()
end

Class Method Details

.call(context, args = []) ⇒ Object



12
# File 'lib/sevgi/standard/errors.rb', line 12

def self.call(context, args = []) = raise new(context, args)

.variant(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sevgi/standard/errors.rb', line 14

def self.variant(message)
  Class.new(self) do
    define_method(:message) do
      [@context, message]
        .tap do |messages|
          messages << @args.map { "'#{it}'" }.join(", ") unless @args.empty?
        end
        .join(": ")
    end
  end
end