Class: Pundit::Matchers::AttributesMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Pundit::Matchers::AttributesMatcher
- Defined in:
- lib/pundit/matchers/attributes_matcher.rb
Overview
The AttributesMatcher class is used to test whether a Pundit policy allows or denies access to certain attributes.
Direct Known Subclasses
Constant Summary collapse
- ARGUMENTS_REQUIRED_ERROR =
Error message to be raised when no attributes are specified.
'At least one attribute must be specified'
- ONE_ARGUMENT_REQUIRED_ERROR =
Error message to be raised when only one attribute may be specified.
'Only one attribute may be specified'
Constants inherited from BaseMatcher
BaseMatcher::AMBIGUOUS_NEGATED_MATCHER_ERROR
Instance Method Summary collapse
-
#ensure_single_attribute! ⇒ AttributesMatcher
Ensures that only one attribute is specified.
-
#for_action(action) ⇒ AttributesMatcher
Specifies the action to be tested.
-
#initialize(*expected_attributes) ⇒ AttributesMatcher
constructor
Initializes a new instance of the AttributesMatcher class.
Constructor Details
#initialize(*expected_attributes) ⇒ AttributesMatcher
Initializes a new instance of the AttributesMatcher class.
17 18 19 20 21 22 23 |
# File 'lib/pundit/matchers/attributes_matcher.rb', line 17 def initialize(*expected_attributes) raise ArgumentError, ARGUMENTS_REQUIRED_ERROR if expected_attributes.empty? super() @expected_attributes = flatten_attributes(expected_attributes) @options = {} end |
Instance Method Details
#ensure_single_attribute! ⇒ AttributesMatcher
Ensures that only one attribute is specified.
39 40 41 42 43 |
# File 'lib/pundit/matchers/attributes_matcher.rb', line 39 def ensure_single_attribute! raise ArgumentError, ONE_ARGUMENT_REQUIRED_ERROR if expected_attributes.size > 1 self end |
#for_action(action) ⇒ AttributesMatcher
Specifies the action to be tested.
29 30 31 32 |
# File 'lib/pundit/matchers/attributes_matcher.rb', line 29 def for_action(action) @options[:action] = action self end |