Module: ToNetMeApi::Result
- Defined in:
- lib/to_net_me_api/result.rb
Overview
A module that handles method result processing.
It implements method blocks support, result typecasting and raises ‘ToNetMeApi::Error` in case of an error response.
Class Method Summary collapse
-
.process(response, type, block) ⇒ Array, Hashie::Mash
The main method result processing.
Class Method Details
.process(response, type, block) ⇒ Array, Hashie::Mash
The main method result processing.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/to_net_me_api/result.rb', line 13 def process(response, type, block) result = extract_result(response) if result.respond_to?(:each) # enumerable result receives :map with a block when called with a block # or is returned untouched otherwise block.nil? ? result : result.map(&block) else # non-enumerable result is typecasted # (and yielded if block_given?) result = typecast(result, type) block.nil? ? result : block.call(result) end end |