Class: Reaction::EachValidator
- Inherits:
-
Object
- Object
- Reaction::EachValidator
- Defined in:
- lib/reaction/each_validator.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Cleanup is provided in case you need to create files that require cleanup after the action has been performed.
-
#initialize(options = {}) ⇒ EachValidator
constructor
A new instance of EachValidator.
-
#validate_each(record, attribute, value) ⇒ Object
If you need to validate a parameter outside of the basic type then validators are your best bet.
Constructor Details
#initialize(options = {}) ⇒ EachValidator
5 6 7 |
# File 'lib/reaction/each_validator.rb', line 5 def initialize( = {}) = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/reaction/each_validator.rb', line 3 def end |
Instance Method Details
#cleanup ⇒ Object
Cleanup is provided in case you need to create files that require cleanup after the action has been performed. For example, Paid creates Tempfiles with some types and uses the cleanup phase to ensure these files get closed up properly.
40 41 |
# File 'lib/reaction/each_validator.rb', line 40 def cleanup end |
#validate_each(record, attribute, value) ⇒ Object
If you need to validate a parameter outside of the basic type then validators are your best bet. They are generally very similar to Rails’ EachValidator. You provide a validate_each method that takes in a record, attribute, and value and then if the attribute isn’t valid adds an error to record.errors. You can also access the data provided for the validator via the options method.
Example validate_each method for a RequiredValidator which would be used like:
param :cat, required: true
param :dog, required: false
def validate_each(record, attribute, value)
if && value.nil?
record.errors.add(attribute, 'is required.')
end
end
30 31 32 |
# File 'lib/reaction/each_validator.rb', line 30 def validate_each(record, attribute, value) raise NotImplementedError.new('Subclasses must implement a validate_each(record, attribute, value) method') end |