Class: Pundit::Matchers::ActionsMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Pundit::Matchers::ActionsMatcher
- Defined in:
- lib/pundit/matchers/actions_matcher.rb
Overview
This is the base action matcher class. Matchers related to actions should inherit from this class.
Direct Known Subclasses
ForbidOnlyActionsMatcher, PermitActionsMatcher, PermitOnlyActionsMatcher
Constant Summary collapse
- ACTIONS_NOT_IMPLEMENTED_ERROR =
Error message when actions are not implemented in a policy.
"'%<policy>s' does not implement %<actions>s"
- ARGUMENTS_REQUIRED_ERROR =
Error message when at least one action must be specified.
'At least one action must be specified'
- ONE_ARGUMENT_REQUIRED_ERROR =
Error message when only one action may be specified.
'Only one action may be specified'
Constants inherited from BaseMatcher
BaseMatcher::AMBIGUOUS_NEGATED_MATCHER_ERROR
Instance Method Summary collapse
-
#ensure_single_action! ⇒ ActionsMatcher
Ensures that only one action is specified.
-
#initialize(*expected_actions) ⇒ ActionsMatcher
constructor
Initializes a new instance of the ActionsMatcher class.
Constructor Details
#initialize(*expected_actions) ⇒ ActionsMatcher
Initializes a new instance of the ActionsMatcher class.
21 22 23 24 25 26 |
# File 'lib/pundit/matchers/actions_matcher.rb', line 21 def initialize(*expected_actions) raise ArgumentError, ARGUMENTS_REQUIRED_ERROR if expected_actions.empty? super() @expected_actions = expected_actions.flatten.map(&:to_sym).sort end |
Instance Method Details
#ensure_single_action! ⇒ ActionsMatcher
Ensures that only one action is specified.
33 34 35 36 37 |
# File 'lib/pundit/matchers/actions_matcher.rb', line 33 def ensure_single_action! raise ArgumentError, ONE_ARGUMENT_REQUIRED_ERROR if expected_actions.size > 1 self end |