Class: Keka::Context
- Inherits:
-
Object
- Object
- Keka::Context
- Defined in:
- lib/keka/context.rb
Defined Under Namespace
Modules: Originable
Instance Method Summary collapse
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #rescue_with(err_class, err_msg = nil) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
14 15 16 17 18 |
# File 'lib/keka/context.rb', line 14 def initialize @opts = { rescue_exceptions: [] } end |
Instance Method Details
#rescue_with(err_class, err_msg = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/keka/context.rb', line 20 def rescue_with(err_class, err_msg = nil) opts[:rescue_exceptions] << { klass: err_class, msg: err_msg } self end |
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/keka/context.rb', line 28 def run raise 'Block required!' unless block_given? yield Keka.ok_result rescue Keka::Halt => e e.result rescue StandardError => e raise unless matched = opts[:rescue_exceptions].detect { |setting| e.is_a?(setting[:klass]) } Keka.err_result(matched[:msg]) end |