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'
Constants inherited from BaseMatcher
BaseMatcher::AMBIGUOUS_NEGATED_MATCHER_ERROR
Instance Method Summary collapse
-
#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.
15 16 17 18 19 20 21 |
# File 'lib/pundit/matchers/attributes_matcher.rb', line 15 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
#for_action(action) ⇒ AttributesMatcher
Specifies the action to be tested.
27 28 29 30 |
# File 'lib/pundit/matchers/attributes_matcher.rb', line 27 def for_action(action) @options[:action] = action self end |