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
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 |
# File 'lib/declarative_authorization/maintenance.rb', line 59 def self.usages_by_controller # load each application controller begin Dir.glob(File.join(::Rails.root, 'app', 'controllers', '**', '*_controller\.rb')) do |entry| require entry end rescue Errno::ENOENT end controllers = ObjectSpace.each_object(Class).select do |obj| obj.ancestors.include?(ActionController::Base) && obj != ActionController::Base && (!obj.name || obj.name.demodulize != 'ApplicationController') 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.private_methods 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 |