title: Ruby Interface, Collection of Objects
body: <p>I have created an interface called <code>Collection</code> to hold in a collection of any objects from my project's models. I want this collection vs an array as I want other fields in <code>Collection</code>.</p>
  
  <pre><code>    module Collection
        def self.included(klass)
          klass.attr_writer :list, type: Array
          klass.attr_writer :class_type,   type: Class
          # Other fields go in here, along with their validations
          klass.validate :validate_list
  
          def validate_list
            self.list.each { |o|
              if(!o.instance_of? self.class_type)
                klass.errors.add :list, 'Objects in list must be of the same type'
                return
              end
            }
          end
        end
      end
  </code></pre>
  
  <p>I want to use this <code>Collection</code> to hold a list of Models::Company 's objects, apart from other lists which I will add to Portfolio Model in the future. I want this list of companies to be only a part of the Portfolio Model.</p>
  
  <pre><code>class Portfolio
    include Model::Collection
  
    @schema = {
        'type' =&gt; 'object',
        'properties' =&gt; {
            'id'                       =&gt; { 'type' =&gt; 'string' },
            'title'                    =&gt; { 'type' =&gt; 'string'  },
            'description'              =&gt; { 'type' =&gt; 'string'  },
            'companies_list'          =&gt;  {'type' =&gt; '?'}, # 1. Should this be array or Collections?
        }
    }
    @modelName      = 'portfolios'
    @collectionName = 'portfolios'
  
  
    store_in collection: 'portfolios'
  
    field :title,                     type: String
    field :description,               type: String
    field :companies_list,            type: Array # 2. Should this be array or array of Collections?
  
    embeds_many :companies
  
  end
  </code></pre>
  
  <p>Any help is appreciated.</p>