app/controllers/eivo/concerns/resources.rb in eivo-rails-api-0.0.5 vs app/controllers/eivo/concerns/resources.rb in eivo-rails-api-0.0.6

- old
+ new

@@ -3,27 +3,33 @@ module EIVO module Concerns module Resources extend ::ActiveSupport::Concern + include EIVO::Concerns::Pagination + included do before_action :set_default_serializer_options end - def index + def index(options = {}) @objects ||= collection_index - unless ::ActiveModel::Type::Boolean.new.cast(params[:pagination]) == false - limit = 50 - if params[:limit] - limit = [[params[:limit].to_i, 1].max, 500].min - end + @objects = paginate(@objects) unless options[:paginate] == false - @objects = @objects.page(params[:page]).per(limit) - @serializer_options.merge!(pagination_options(@objects)) - end + if options[:cache] && options[:cache] != false + if options[:cache].is_a?(Hash) + cache_options = options[:cache] + else + cache_options = {} + end - render_success serializer.new(@objects, @serializer_options) + if stale?(@objects, public: cache_options.fetch(:public, false)) + render_success serializer.new(@objects, @serializer_options) + end + else + render_success serializer.new(@objects, @serializer_options) + end end def show @object ||= collection.find(params[:id]) render_success serializer.new(@object, @serializer_options)