Module: Authorization::Maintenance::Usage
- Defined in:
- lib/declarative_authorization/maintenance.rb
Overview
Module for grouping usage-related helper methods
Class Method Summary collapse
-
.usages_by_controller ⇒ Object
Delivers a hash of => usage_info_hash, where usage_info_hash has the form of.
Class Method Details
.usages_by_controller ⇒ Object
Delivers a hash of => usage_info_hash, where usage_info_hash has the form of
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/declarative_authorization/maintenance.rb', line 57 def self.usages_by_controller # load each application controller begin Dir.foreach(File.join(RAILS_ROOT, %w{app controllers})) do |entry| if entry =~ /^\w+_controller\.rb$/ require File.join(RAILS_ROOT, %w{app controllers}, entry) end end rescue Errno::ENOENT end controllers = [] ObjectSpace.each_object(Class) do |obj| controllers << obj if obj.ancestors.include?(ActionController::Base) and !%w{ActionController::Base ApplicationController}.include?(obj.name) end controllers.inject({}) do |memo, controller| = [] = {} controller..each do || << if .actions.include?(:all) .actions.reject {|action| action == :all}.each do |action| [action] = end end actions = controller.public_instance_methods(false) - controller.hidden_actions memo[controller] = actions.inject({}) do |actions_memo, action| action_sym = action.to_sym actions_memo[action_sym] = if [action_sym] { :privilege => [action_sym].privilege, :context => [action_sym].context, :controller_permissions => [[action_sym]] } elsif !.empty? { :privilege => [0].privilege, :context => [0].context, :controller_permissions => } else {} end actions_memo end memo end end |