Exception: 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



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

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

.variant(message) ⇒ Object



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

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