class Api::BaseController < ApiController
  responders OpenMensa::Responders::ApiResponder,
    Responders::DecorateResponder,
    Responders::PaginateResponder

  api_version 2

  class << self
    attr_accessor :max_limit, :default_limit, :default_page
  end

  # **** api responders ****

  def resource
    @resource ||= find_resource
  end

  def collection
    @collection ||= find_collection
  end

  def default_scope(scope)
    scope
  end

  def scoped_resource
    default_scope(self.class.resource_class.scoped)
  end

  def find_resource
    scoped_resource.find params[:id]
  end

  def find_collection
    collection = default_scope(self.class.resource_class.scoped)
    collection = apply_scopes(collection) if respond_to? :apply_scopes
    collection
  end

  def self.resource_name
    @resource_name ||= controller_name.singularize.capitalize
  end

  def self.resource_class
    @resource_class ||= ActiveSupport::Inflector.constantize resource_name
  end

  def self.decorator_class
    @decorator_class ||= ActiveSupport::Inflector.constantize(resource_name + 'Decorator')
  end

  # **** default api actions ****

  def index
    respond_with self.collection
  end

  def show
    respond_with self.resource
  end

  # paginate reponder methods

  def max_per_page
    100
  end

  def per_page
    params[:per_page].try(:to_i) || params[:limit].try(:to_i) || 50
  end
end

class Api::BaseController < ApiController
  responders OpenMensa::Responders::ApiResponder,
    Responders::DecorateResponder,
    Responders::PaginateResponder

  api_version 2

  class << self
    attr_accessor :max_limit, :default_limit, :default_page
  end

  # **** api responders ****

  def resource
    @resource ||= find_resource
  end

  def collection
    @collection ||= find_collection
  end

  def default_scope(scope)
    scope
  end

  def scoped_resource
    default_scope(self.class.resource_class.scoped)
  end

  def find_resource
    scoped_resource.find params[:id]
  end

  def find_collection
    collection = default_scope(self.class.resource_class.scoped)
    collection = apply_scopes(collection)
    collection
  end

  def self.resource_name
    @resource_name ||= controller_name.singularize.capitalize
  end

  def self.resource_class
    @resource_class ||= ActiveSupport::Inflector.constantize resource_name
  end

  def self.decorator_class
    @decorator_class ||= ActiveSupport::Inflector.constantize(resource_name + 'Decorator')
  end

  # **** default api actions ****

  def index
    respond_with self.collection
  end

  def show
    respond_with self.resource
  end

  # paginate reponder methods

  def max_per_page
    100
  end

  def per_page
    params[:per_page].try(:to_i) || params[:limit].try(:to_i) || 50
  end
end

Remove respond_to? :apply_scopes as it returns false on Ruby 2.0.0.
Remove respond_to? :apply_scopes as it returns false on Ruby 2.0.0.
