Sha256: 02b62dfb588f96f7b5fae16ac05c7314c83623dfa1f452f3c3bc2438f575a28e

Contents?: true

Size: 563 Bytes

Versions: 1

Compression:

Stored size: 563 Bytes

Contents

module ActiveHashRelation::SortFilters
  def apply_sort(resource, params, model = nil)
    if params.is_a? Array
      params.each do |param_item|
        resource = apply_hash_sort(resource, param_item, model)
      end
    else
      resource = apply_hash_sort(resource, params, model)
    end

    return resource
  end

  def apply_hash_sort(resource, params, model = nil)
    if model.columns.map(&:name).include?(params[:property].to_s)
      resource = resource.order(params[:property] => (params[:order] || :desc) )
    end

    return resource
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_hash_relation-1.2.0 lib/active_hash_relation/sort_filters.rb