class DTK::Client::Response
Public Class Methods
new(hash = {})
click to toggle source
Calls superclass method
# File lib/client/response.rb, line 31 def initialize(hash = {}) super(hash) @print_error_table = false #we use it if we want to print 'error legend' for given tables render_attributes_init! end
wrap_as_response(data = {}) { |: data)| ... }
click to toggle source
This method is used so that client side actions can be wrapped like calls to server
# File lib/client/response.rb, line 44 def self.wrap_as_response(data = {}, &block) results = (block ? yield : data) if results.nil? NoOp.new elsif results.kind_of?(Response) results else Ok.new(results) end end
Public Instance Methods
error_info?(opts = {})
click to toggle source
opts can be
:default_error_if_nil - Boolean
# File lib/client/response.rb, line 39 def error_info?(opts = {}) ErrorHandler.error_info?(self, opts) end
index_data(*indexes)
click to toggle source
# File lib/client/response.rb, line 59 def index_data(*indexes) index_common(*indexes) { |_indexes| nil } end
notok?()
click to toggle source
# File lib/client/response.rb, line 55 def notok? kind_of?(NotOk) end
required(*indexes)
click to toggle source
# File lib/client/response.rb, line 63 def required(*indexes) index_common(*indexes) do |indexes| raise Error, "Missing response field 'response[:#{indexes.join('][:')}]'" end end
Private Instance Methods
index_common(*indexes, &block_when_no_data)
click to toggle source
# File lib/client/response.rb, line 71 def index_common(*indexes, &block_when_no_data) if indexes.empty? raise Error, 'indexes should not be empty' else val = data indexes.each do |key| unless val.kind_of?(::Hash) and val.has_key?(key.to_s) return block_when_no_data.call(indexes) end val = val[key.to_s] end val end end