Module: Scorpio::ResourceBase::Containment

Includes:
JSI::Util::Private::FingerprintHash
Included in:
Scorpio::ResourceBase, Container
Defined in:
lib/scorpio/resource_base.rb

Instance Method Summary collapse

Instance Method Details

#[](key, _: nil) ⇒ Object

unused keyword param lets an empty keyword hash be passed in older ruby versions



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/scorpio/resource_base.rb', line 404

def [](key, _: nil) # unused keyword param lets an empty keyword hash be passed in older ruby versions
  sub = contained_object[key]
  if sub.is_a?(JSI::Base)
    # TODO avoid reinstantiating the container only to throw it away if it matches the memo
    sub_container = @openapi_document_class.response_object_to_instances(sub, options)

    if @subscript_memos.key?(key) && @subscript_memos[key].class == sub_container.class
      @subscript_memos[key]
    else
      @subscript_memos[key] = sub_container
    end
  else
    sub
  end
end

#[]=(key, value) ⇒ Object



420
421
422
423
424
425
426
427
# File 'lib/scorpio/resource_base.rb', line 420

def []=(key, value)
  @subscript_memos.delete(key)
  if value.is_a?(Containment)
    contained_object[key] = value.contained_object
  else
    contained_object[key] = value
  end
end

#as_json(*opt) ⇒ Object



429
430
431
# File 'lib/scorpio/resource_base.rb', line 429

def as_json(*opt)
  JSI::Util.as_json(contained_object, *opt)
end

#inspectObject



433
434
435
# File 'lib/scorpio/resource_base.rb', line 433

def inspect
  -"\#<#{self.class.inspect} #{contained_object.inspect}>"
end

#jsi_fingerprintObject



453
454
455
# File 'lib/scorpio/resource_base.rb', line 453

def jsi_fingerprint
  {class: self.class, contained_object: as_json}
end

#pretty_print(q) ⇒ Object



437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/scorpio/resource_base.rb', line 437

def pretty_print(q)
  q.instance_exec(self) do |obj|
    text(-"\#<#{obj.class.inspect}")
    group_sub {
      nest(2) {
        breakable ' '
        pp obj.contained_object
      }
    }
    breakable ''
    text '>'
  end
end