class Fixturama::Changes::Chain::RaiseAction

@private Raise a specified exception as a result of stubbing

Attributes

repeat[R]

Public Class Methods

new(**options) click to toggle source
   # File lib/fixturama/changes/chain/raise_action.rb
15 def initialize(**options)
16   @error  = error_from options
17   @repeat = repeat_from options
18 rescue StandardError => err
19   raise Fixturama::FixtureError.new("an exception class", options, err)
20 end

Public Instance Methods

call() click to toggle source
   # File lib/fixturama/changes/chain/raise_action.rb
 9 def call
10   raise @error
11 end

Private Instance Methods

error_from(options) click to toggle source
   # File lib/fixturama/changes/chain/raise_action.rb
22 def error_from(options)
23   klass  = klass_from(options)
24   params = options[:arguments]
25   params.is_a?(Array) ? klass.new(*params) : klass
26 end
klass_from(options) click to toggle source
   # File lib/fixturama/changes/chain/raise_action.rb
28 def klass_from(options)
29   klass = case value = options[:raise]
30           when NilClass, TrueClass, "true" then StandardError
31           when Class then value
32   else Kernel.const_get(value)
33   end
34 
35   klass < Exception ? klass : raise("#{klass} is not an exception")
36 end
repeat_from(options) click to toggle source
   # File lib/fixturama/changes/chain/raise_action.rb
38 def repeat_from(options)
39   options.fetch(:repeat, 1).to_i.tap { |val| return val if val.positive? }
40   raise Fixturama::FixtureError.new("a number of repeats", options)
41 end