Method: Spider::Model.sort

Defined in:
lib/spiderfw/model/model.rb

.sort(models, options = {}) ⇒ Array

Sorts an Array of models, placing subclasses before superclasses.

If :association_dependencies is true, models having an association to another model will be placed after the associated model.

This can be used to insert a dump of data, ensuring later models only depend on already inserted objects.

Parameters:

  • models (Array)

    An array of BaseModel subclasses

  • options (Hash) (defaults to: {})

    Options can be:

    • :association_dependencies If true, sort associated models before the model associating them

Returns:

  • (Array)

    The sorted array



375
376
377
378
379
380
381
# File 'lib/spiderfw/model/model.rb', line 375

def self.sort(models, options={})
    options = {
        :association_dependencies => true
    }.merge(options)
    sorter = Sorter.new(models, options)
    sorter.sort
end