Class: Authz::ControllerAction
- Inherits:
-
Authz.selfself::ApplicationRecord
- Object
- Authz.selfself::ApplicationRecord
- Authz::ControllerAction
- Defined in:
- app/models/authz/controller_action.rb
Overview
Represents a single reachable controller action from the host application’s router, including all library internal routes.
Class Method Summary collapse
-
.engine_reachable_controller_actions ⇒ Hash
Reachable controller actions declared in the Engine’s router.
-
.main_app_reachable_controller_actions ⇒ Hash
Reachable controller actions declared in the host app’s router.
-
.pending ⇒ Array<Hash<controller_name, action_name>>
private
Controller actions reachable from the router but not present in the database.
-
.reachable_controller_actions ⇒ Hash
Combines the reachable controller actions from the engine and the main app giving precedence to the main app in case of overwrite.
-
.stale ⇒ Array<Authz::ControllerAction>
private
Controller actions that are created in the database that are no longer reachable from the router.
Instance Method Summary collapse
-
#to_s ⇒ String
Concatenation of controller#action-id.
Class Method Details
.engine_reachable_controller_actions ⇒ Hash
Returns reachable controller actions declared in the Engine’s router.
42 43 44 |
# File 'app/models/authz/controller_action.rb', line 42 def self.engine_reachable_controller_actions extract_reachable_controller_actions(Authz::Engine) end |
.main_app_reachable_controller_actions ⇒ Hash
Returns reachable controller actions declared in the host app’s router.
37 38 39 |
# File 'app/models/authz/controller_action.rb', line 37 def self.main_app_reachable_controller_actions extract_reachable_controller_actions(Rails.application) end |
.pending ⇒ Array<Hash<controller_name, action_name>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns controller actions reachable from the router but not present in the database.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/authz/controller_action.rb', line 64 def self.pending # TODO: Refactor and test ca_pairs = [] reachable_controller_actions.each do | c_name, action_arr | action_arr.each do |a_name| ca_pairs << { controller: c_name, action: a_name } end end pending = [] ca_pairs.each do |route| ca = find_by(controller: route[:controller], action: route[:action]) pending << route unless ca end pending end |
.reachable_controller_actions ⇒ Hash
Combines the reachable controller actions from the engine and the main app giving precedence to the main app in case of overwrite
51 52 53 54 55 56 57 58 |
# File 'app/models/authz/controller_action.rb', line 51 def self.reachable_controller_actions app_cas = main_app_reachable_controller_actions engine_cas = engine_reachable_controller_actions repeated_keys = app_cas.keys & engine_cas.keys res = engine_cas.merge(app_cas) repeated_keys.each { |rk| res[rk] = app_cas[rk] | engine_cas[rk] } res end |
.stale ⇒ Array<Authz::ControllerAction>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns controller actions that are created in the database that are no longer reachable from the router.
86 87 88 89 90 91 92 93 94 |
# File 'app/models/authz/controller_action.rb', line 86 def self.stale # TODO: Refactor and test stale = [] find_each do |ca| is_included = reachable_controller_actions[ca.controller].try(:include?, ca.action) stale << ca unless is_included end stale end |
Instance Method Details
#to_s ⇒ String
Returns concatenation of controller#action-id.
100 101 102 |
# File 'app/models/authz/controller_action.rb', line 100 def to_s "#{controller}##{action}-#{id}" end |