Class: Scorpio::ResourceBase::Container

Inherits:
Object
  • Object
show all
Includes:
Containment
Defined in:
lib/scorpio/resource_base.rb,
lib/scorpio/resource_base.rb

Defined Under Namespace

Modules: Array, Hash

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Containment

#[], #[]=, #as_json, #inspect, #jsi_fingerprint, #pretty_print

Constructor Details

#initialize(contained_object, openapi_document_class, options = {}) ⇒ Container

Returns a new instance of Container.



589
590
591
592
593
594
# File 'lib/scorpio/resource_base.rb', line 589

def initialize(contained_object, openapi_document_class, options = {})
  @contained_object = contained_object
  @openapi_document_class = openapi_document_class
  @options = options
  @subscript_memos = {}
end

Instance Attribute Details

#contained_objectObject (readonly) Also known as: jsi_node_content

Returns the value of attribute contained_object.



596
597
598
# File 'lib/scorpio/resource_base.rb', line 596

def contained_object
  @contained_object
end

#optionsObject (readonly)

Returns the value of attribute options.



598
599
600
# File 'lib/scorpio/resource_base.rb', line 598

def options
  @options
end

Class Method Details

.new_container(object, openapi_document_class, options = {}) ⇒ Object



517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/scorpio/resource_base.rb', line 517

def new_container(object, openapi_document_class, options = {})
  container_modules = Set[]

  if object.respond_to?(:to_hash)
    container_modules << Container::Hash
  end
  if object.respond_to?(:to_ary)
    container_modules << Container::Array
  end

  container_class = @container_classes[{modules: container_modules.freeze, schemas: object.jsi_schemas}]

  container_class.new(object, openapi_document_class, options)
end

Instance Method Details

#jsi_object_group_textArray<String>

Returns:



606
607
608
609
610
611
612
613
# File 'lib/scorpio/resource_base.rb', line 606

def jsi_object_group_text
  schema_names = contained_object.jsi_schemas.map { |schema| schema.jsi_schema_module.name_from_ancestor || schema.schema_uri }.compact
  if schema_names.empty?
    [Container.to_s]
  else
    ["#{Container} (#{schema_names.join(', ')})"]
  end
end