-
-
Save toidang92/af77a8d8566c4f6c652a to your computer and use it in GitHub Desktop.
Rake task to list ActiveAdmin resource and page actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :active_admin_actions => :environment do | |
skip_resources = [ 'Dashboard' ] | |
namespace = ActiveAdmin.application.namespace(:admin) | |
pages = namespace.resources.select { |r| r.is_a? ActiveAdmin::Page } | |
resources = namespace.resources.select { |r| r.respond_to? :resource_class } | |
resource_actions = | |
resources.each_with_object({}) do |resource, actions| | |
resource_name = resource.resource_class.name | |
if !skip_resources.include? resource_name | |
actions[resource_name] = resource.defined_actions | |
actions[resource_name].concat resource.member_actions.map { |action| action.name } | |
actions[resource_name].concat resource.collection_actions.map { |action| action.name } | |
end | |
end | |
puts resource_actions.inspect | |
page_actions = | |
pages.each_with_object({}) do |page, actions| | |
page_name = page.name | |
if !skip_resources.include? page_name | |
actions[page_name] = page.page_actions + [:index] | |
end | |
end | |
puts page_actions.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment