Exception: ArtirixDataModels::DataGateway::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/artirix_data_models/gateways/data_gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Error

Returns a new instance of Error.



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 286

def initialize(*args)
  case args.size
  when 0
    message = nil
    options = {}
  when 1
    if args.first.kind_of? Hash
      options = args.first
      message = nil
    else
      message = args.first
      options = {}
    end
  else
    message = args[0]
    options = args[1]

    if message.kind_of? Hash
      options, message = message, options
    end
  end

  if message.present?
    options[:message] = message
  end

  build_from_options(options) if options.present?
end

Instance Attribute Details

#messageObject (readonly) Also known as: msg

Returns the value of attribute message.



282
283
284
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 282

def message
  @message
end

#methodObject (readonly)

Returns the value of attribute method.



282
283
284
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 282

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



282
283
284
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 282

def path
  @path
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



282
283
284
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 282

def response_body
  @response_body
end

#response_statusObject (readonly)

Returns the value of attribute response_status.



282
283
284
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 282

def response_status
  @response_status
end

Instance Method Details

#data_hashObject



339
340
341
342
343
344
345
346
347
348
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 339

def data_hash
  {
    class:           self.class.to_s,
    path:            path,
    method:          method,
    response_status: response_status,
    response_body:   response_body,
    message:         message,
  }
end

#json_response_bodyObject



315
316
317
318
319
320
321
322
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 315

def json_response_body
  return nil unless response_body.present?

  Oj.load response_body, symbol_keys: true

rescue Oj::Error # in case it's not json
  nil
end

#matches?(other) ⇒ Boolean

for testing

Returns:

  • (Boolean)


351
352
353
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 351

def matches?(other)
  other.kind_of? self.class
end

#to_sObject



324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 324

def to_s
  msg = super
  msg = nil if msg == self.class.to_s

  parts = {
    path:            path,
    method:          method,
    response_status: response_status,
    response_body:   response_body,
    message:         message,
  }.select { |_, v| v.present? }.map { |k, v| "#{k}: #{v.inspect}" }

  "#{self.class}: #{parts.join ', '}"
end