Module: Shamu::Attributes::Validation
- Extended by:
- ActiveSupport::Concern
- Included in:
- Entities::ListScope, JsonApi::Rails::Pagination, Services::Request
- Defined in:
- lib/shamu/attributes/validation.rb
Overview
Defines an interface for entities that report validation failures with respect to their attributes.
Defined Under Namespace
Modules: Overrides
Class Method Summary collapse
-
.attribute(name, build, **options) ⇒ Object
Adds validation options to Attributes::DSL#attribute.
Instance Method Summary collapse
-
#valid? ⇒ Boolean
If the object is free from validation errors.
-
#validated? ⇒ Boolean
True if the object has been validated at least once.
Class Method Details
.attribute(name, build, **options) ⇒ Object
Adds validation options to Attributes::DSL#attribute. Any option not recognized by one of the Attributes mixins will be used as validation arguments for the given attribute.
45 46 47 48 49 50 51 52 |
# File 'lib/shamu/attributes/validation.rb', line 45 def attribute( name, *args, **, &block ) super = .each_with_object({}) do |(key, value), opts| opts[key] = value unless attribute_option_keys.include?( key ) end validates name, if .any? end |
Instance Method Details
#valid? ⇒ Boolean
Returns if the object is free from validation errors. Must call #validate before checking.
20 21 22 |
# File 'lib/shamu/attributes/validation.rb', line 20 def valid? errors.blank? end |
#validated? ⇒ Boolean
Returns true if the object has been validated at least once.
25 26 27 |
# File 'lib/shamu/attributes/validation.rb', line 25 def validated? @validated end |