Class: Reaction::Type
- Inherits:
-
Object
- Object
- Reaction::Type
- Defined in:
- lib/reaction/type.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
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.
-
#convert(value) ⇒ Object
Convert is used to transform a value into whatever format you expect it to be.
-
#initialize(name) ⇒ Type
constructor
A new instance of Type.
-
#validate_each(record, attribute, value) ⇒ Object
If you need to validate based on type you can.
Constructor Details
#initialize(name) ⇒ Type
Returns a new instance of Type.
5 6 7 |
# File 'lib/reaction/type.rb', line 5 def initialize(name) @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/reaction/type.rb', line 3 def name @name 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.
37 38 |
# File 'lib/reaction/type.rb', line 37 def cleanup end |
#convert(value) ⇒ Object
Convert is used to transform a value into whatever format you expect it to be. For example, you might have a convert method that casts a string into an integer, or one that takes in various date formats and converts them to a DateTime prior to the param being used in the action.
27 28 29 |
# File 'lib/reaction/type.rb', line 27 def convert(value) value end |
#validate_each(record, attribute, value) ⇒ Object
If you need to validate based on type you can. These work identically to the validators, except type validations are always called before other validators, and the options
hash isn’t available. If you have a particularly good use case for passing in options to a Type reach out; It should be pretty easy to add in, we just haven’t had a need for it yet.
17 18 |
# File 'lib/reaction/type.rb', line 17 def validate_each(record, attribute, value) end |