Sha256: 08c87eca6671af6b6aa252e0de6a599e42ca6ec99a31226e8a93dc5afe551229

Contents?: true

Size: 750 Bytes

Versions: 21

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true
require 'drillbit/parameters/sort'

module  Drillbit
module  Resource
module  Processors
class   Sorting
  attr_accessor :resource,
                :parameters

  # rubocop:disable Style/OptionHash
  def initialize(resource, parameters = {})
    self.resource   = resource
    self.parameters = Parameters::Sort.new(parameters['sort'])
  end
  # rubocop:enable Style/OptionHash

  def self.processed(*attrs)
    new(*attrs).processed
  end

  def self.meta(*attrs)
    new(*attrs).meta
  end

  def processed
    return resource unless parameters.present?

    resource.order(parameters.to_h)
  end

  def meta
    return {} unless parameters.present?

    {
      'sort' => parameters.to_h,
    }
  end
end
end
end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
drillbit-2.11.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.10.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.9.1 lib/drillbit/resource/processors/sorting.rb
drillbit-2.9.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.8.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.7.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.6.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.5.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.4.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.3.1 lib/drillbit/resource/processors/sorting.rb
drillbit-2.3.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.2.2 lib/drillbit/resource/processors/sorting.rb
drillbit-2.2.1 lib/drillbit/resource/processors/sorting.rb
drillbit-2.2.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.1.0 lib/drillbit/resource/processors/sorting.rb
drillbit-2.0.1 lib/drillbit/resource/processors/sorting.rb
drillbit-2.0.0 lib/drillbit/resource/processors/sorting.rb
drillbit-1.1.0 lib/drillbit/resource/processors/sorting.rb
drillbit-1.0.1 lib/drillbit/resource/processors/sorting.rb
drillbit-1.0.0 lib/drillbit/resource/processors/sorting.rb