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
-
#[](key, _: nil) ⇒ Object
unused keyword param lets an empty keyword hash be passed in older ruby versions.
- #[]=(key, value) ⇒ Object
- #as_json(*opt) ⇒ Object
- #inspect ⇒ Object
- #jsi_fingerprint ⇒ Object
- #pretty_print(q) ⇒ Object
Instance Method Details
#[](key, _: nil) ⇒ Object
unused keyword param lets an empty keyword hash be passed in older ruby versions
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/scorpio/resource_base.rb', line 395 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, ) 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
411 412 413 414 415 416 417 418 |
# File 'lib/scorpio/resource_base.rb', line 411 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
420 421 422 |
# File 'lib/scorpio/resource_base.rb', line 420 def as_json(*opt) JSI::Util.as_json(contained_object, *opt) end |
#inspect ⇒ Object
424 425 426 |
# File 'lib/scorpio/resource_base.rb', line 424 def inspect "\#<#{self.class.inspect} #{contained_object.inspect}>" end |
#jsi_fingerprint ⇒ Object
444 445 446 |
# File 'lib/scorpio/resource_base.rb', line 444 def jsi_fingerprint {class: self.class, contained_object: as_json} end |
#pretty_print(q) ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/scorpio/resource_base.rb', line 428 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 |