Sha256: 2909304e54fb264a32d1d601299bc636f001ca2fccb554ff5372ad8ad8195249

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 Bytes

Contents

# Adapter for the `ransack` gem.
class RESTFramework::RansackFilter < RESTFramework::BaseFilter
  # Filter data according to the request query parameters.
  def get_filtered_data(data)
    q = @controller.request.query_parameters[@controller.ransack_query_param]

    if q.present?
      distinct = @controller.ransack_distinct

      # Determine if `distinct` is determined by query param.
      if distinct_query_param = @controller.ransack_distinct_query_param
        if distinct_query = @controller.request.query_parameters[distinct_query_param].presence
          distinct_from_query = ActiveRecord::Type::Boolean.new.cast(distinct_query)
          unless distinct_from_query.nil?
            distinct = distinct_from_query
          end
        end
      end

      return data.ransack(q, @controller.ransack_options || {}).result(distinct: distinct)
    end

    return data
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rest_framework-0.9.7 lib/rest_framework/filters/ransack.rb
rest_framework-0.9.6 lib/rest_framework/filters/ransack.rb