Module: PriceHubble::Utils::Decision
- Extended by:
- ActiveSupport::Concern
- Included in:
- Client::Base
- Defined in:
- lib/price_hubble/utils/decision.rb
Overview
Provides an easy to use decision DSL which works like a flow control. (eg. if conditions, or a switch statement) It should DRY out the processing logic on clients, while make decisions about the status of the response. The decision helper evaluates the answers to: Should we raise an error or return a default value? Was the response any good?
Example:
decision(bang: true) do |result|
result.fail { nil }
result.bang { Hausgold::AuthenticationError.new(nil, res, res.body) }
result.good { Hausgold::Jwt.new(res.body).clear_changes }
successful?(res)
end
Defined Under Namespace
Classes: Runtime
Instance Method Summary collapse
-
#decision(bang: false) { ... } ⇒ Mixed
Allow users to build decision paths and run them according to the result.
Instance Method Details
#decision(bang: false) { ... } ⇒ Mixed
Allow users to build decision paths and run them according to the result. This is a kind of flow control like an if condition, or a switch statement. It contains three decision result paths, the happy case (good), an error case for regular issues (fail) and a error case for fatal issues (bang). You can configure the decision which error behaiviour you prefer by setting the bang
argument to true or false.
34 35 36 37 |
# File 'lib/price_hubble/utils/decision.rb', line 34 def decision(bang: false, &block) runtime = Runtime.new(on_error: bang ? :bang : :fail) runtime.evaluate(&block) end |