module ActiveAdmin::ResourceController::Decorators

def self.undecorate(resource)

def self.undecorate(resource)
  if resource.respond_to?(:decorated?) && resource.decorated?
    resource.model
  else
    resource
  end
end

def apply_collection_decorator(collection)

def apply_collection_decorator(collection)
  if decorate?
    collection_decorator.decorate collection, with: decorator_class
  else
    collection
  end
end

def apply_decorator(resource)

def apply_decorator(resource)
  decorate? ? decorator_class.new(resource) : resource
end

def collection_decorator

correctly delegates methods that Active Admin depends on.
When using Draper, we wrap the collection draper in a new class that
def collection_decorator
  if decorator_class
    Wrapper.wrap decorator_class
  end
end

def decorate?

def decorate?
  case action_name
  when "new", "edit", "create", "update"
    form = active_admin_config.get_page_presenter :form
    form && form.options[:decorate] && decorator_class.present?
  else
    decorator_class.present?
  end
end

def decorator_class

def decorator_class
  active_admin_config.decorator_class
end