Module: RESTFramework::ListModelMixin

Included in:
ModelControllerMixin, ReadOnlyModelControllerMixin
Defined in:
lib/rest_framework/controller_mixins/models.rb

Overview

Mixin for listing records.

Instance Method Summary collapse

Instance Method Details

#get_index_recordsObject

Get records with both filtering and pagination applied.



670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/rest_framework/controller_mixins/models.rb', line 670

def get_index_records
  records = self.get_records

  # Handle pagination, if enabled.
  if self.paginator_class
    # If there is no `max_page_size`, `page_size_query_param` is not `nil`, and the page size is
    # set to "0", then skip pagination.
    unless !self.max_page_size &&
        self.page_size_query_param &&
        params[self.page_size_query_param] == "0"
      paginator = self.paginator_class.new(data: records, controller: self)
      page = paginator.get_page
      serialized_page = self.serialize(page)
      return paginator.get_paginated_response(serialized_page)
    end
  end

  return records
end

#indexObject



665
666
667
# File 'lib/rest_framework/controller_mixins/models.rb', line 665

def index
  return api_response(self.get_index_records)
end