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.



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 322

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)

Returns the value of attribute message.



318
319
320
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 318

def message
  @message
end

#methodObject (readonly)

Returns the value of attribute method.



318
319
320
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 318

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



318
319
320
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 318

def path
  @path
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



318
319
320
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 318

def response_body
  @response_body
end

#response_statusObject (readonly)

Returns the value of attribute response_status.



318
319
320
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 318

def response_status
  @response_status
end

Instance Method Details

#data_hashObject



379
380
381
382
383
384
385
386
387
388
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 379

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



351
352
353
354
355
356
357
358
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 351

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)


391
392
393
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 391

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

#msgObject

Returns the value of attribute message.



320
321
322
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 320

def message
  @message
end

#to_sObject



360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/artirix_data_models/gateways/data_gateway.rb', line 360

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: msg,
  }.select { |_, v| v.present? }.map { |k, v| "#{k}: #{v.inspect}" }

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