Module: Lotus::Validations::ClassMethods
- Defined in:
- lib/lotus/validations.rb
Overview
Validations DSL
Instance Method Summary collapse
-
#defined_attributes ⇒ Array<String>
private
Set of user defined attributes.
-
#included(base) ⇒ Object
private
Override Ruby’s hook for modules.
-
#inherited(base) ⇒ Object
private
Override Ruby’s hook for class inheritance.
-
#validates(name, options) ⇒ Object
Define a validation for an existing attribute.
-
#validations ⇒ Hash
private
Set of user defined validations.
Instance Method Details
#defined_attributes ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set of user defined attributes
135 136 137 |
# File 'lib/lotus/validations.rb', line 135 def defined_attributes validations.names.map(&:to_s) end |
#included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Ruby’s hook for modules. When a module includes Lotus::Validations and it is included in a class or module, this passes the validations from the module to the base.
78 79 80 81 82 83 84 85 86 |
# File 'lib/lotus/validations.rb', line 78 def included(base) base.class_eval do include Lotus::Validations end super transfer_validations_to_base(base) end |
#inherited(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Ruby’s hook for class inheritance. When a class includes Lotus::Validations and it is subclassed, this passes the attributes from the superclass to the subclass.
44 45 46 47 |
# File 'lib/lotus/validations.rb', line 44 def inherited(base) transfer_validations_to_base(base) super end |
#validates(name, options) ⇒ Object
Define a validation for an existing attribute
115 116 117 |
# File 'lib/lotus/validations.rb', line 115 def validates(name, ) validations.add(name, ) end |
#validations ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set of user defined validations
125 126 127 |
# File 'lib/lotus/validations.rb', line 125 def validations @validations ||= ValidationSet.new end |