Class: Porridge::FieldPolicy
- Inherits:
-
Object
- Object
- Porridge::FieldPolicy
- Defined in:
- lib/porridge/field_policy.rb
Overview
FieldPolicy is the nominal base class for all field policy classes.
A field policy is an object that is capable of determining whether a certain “field” is allowed in a given context. Currently, it is primarily used in FieldSerializer as the default method of determining whether a field is valid. You are encouraged, but not required, to have your own custom field policies derive from this class. Currently, any object that implements the #allowed?
method is a valid field policy.
Direct Known Subclasses
Class Method Summary collapse
-
.ensure_valid!(*objects) ⇒ Boolean
Ensures that all the provided objects are valid field policies, raising InvalidFieldPolicyError if not.
-
.valid?(object) ⇒ Boolean
Determines whether the given object is a valid porridge field policy.
Instance Method Summary collapse
-
#allowed?(_name, _object, _options) ⇒ Boolean
Determiners whether the field with the given name for the given object with the given options is currently allowed.
Class Method Details
.ensure_valid!(*objects) ⇒ Boolean
Ensures that all the provided objects are valid field policies, raising InvalidFieldPolicyError if not.
23 24 25 26 |
# File 'lib/porridge/field_policy.rb', line 23 def self.ensure_valid!(*objects) objects.each { |object| raise InvalidFieldPolicyError unless valid?(object) } true end |
.valid?(object) ⇒ Boolean
Determines whether the given object is a valid porridge field policy. Currently, any object that responds to the #allowed?
method is valid.
15 16 17 |
# File 'lib/porridge/field_policy.rb', line 15 def self.valid?(object) object.respond_to? :allowed? end |
Instance Method Details
#allowed?(_name, _object, _options) ⇒ Boolean
Determiners whether the field with the given name for the given object with the given options is currently allowed.
34 35 36 |
# File 'lib/porridge/field_policy.rb', line 34 def allowed?(_name, _object, ) true end |