Class: ActiveElement::PermissionsCheck
- Inherits:
-
Object
- Object
- ActiveElement::PermissionsCheck
- Includes:
- Paintbrush
- Defined in:
- lib/active_element/permissions_check.rb
Overview
Verifies provided permissions against required permissions.
Instance Method Summary collapse
- #applicable ⇒ Object
- #applicable_permissions ⇒ Object
-
#initialize(required:, actual:, controller_path:, action_name:, rails_component:) ⇒ PermissionsCheck
constructor
A new instance of PermissionsCheck.
- #message ⇒ Object
- #missing ⇒ Object
- #missing_permissions ⇒ Object
- #permitted? ⇒ Boolean
Constructor Details
#initialize(required:, actual:, controller_path:, action_name:, rails_component:) ⇒ PermissionsCheck
Returns a new instance of PermissionsCheck.
8 9 10 11 12 13 14 15 |
# File 'lib/active_element/permissions_check.rb', line 8 def initialize(required:, actual:, controller_path:, action_name:, rails_component:) @required = required.presence || [] @actual = normalized(actual) @controller_name = controller_path.to_s.gsub('/', '_') @action_name = action_name.to_s @rails_component = rails_component raise_unprotected_route_error if applicable.empty? end |
Instance Method Details
#applicable ⇒ Object
36 37 38 |
# File 'lib/active_element/permissions_check.rb', line 36 def applicable @applicable ||= + end |
#applicable_permissions ⇒ Object
40 41 42 |
# File 'lib/active_element/permissions_check.rb', line 40 def applicable.map { || .fetch(:with) } end |
#message ⇒ Object
21 22 23 24 25 26 |
# File 'lib/active_element/permissions_check.rb', line 21 def return if rails_component.environment == 'development' return if permitted? end |
#missing ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/active_element/permissions_check.rb', line 28 def missing @missing ||= applicable.reject do || next true if .fetch(:always, false) actual.include?(.fetch(:with).to_s) end end |
#missing_permissions ⇒ Object
44 45 46 |
# File 'lib/active_element/permissions_check.rb', line 44 def missing.map { || .fetch(:with) } end |
#permitted? ⇒ Boolean
17 18 19 |
# File 'lib/active_element/permissions_check.rb', line 17 def permitted? rails_component.environment == 'development' || missing.blank? end |