Class: Reaction::Type

Inherits:
Object
  • Object
show all
Includes:
IsDocumented
Defined in:
lib/reaction/type.rb

Direct Known Subclasses

RawType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IsDocumented

included

Constructor Details

#initialize(name) ⇒ Type

Returns a new instance of Type.



7
8
9
# File 'lib/reaction/type.rb', line 7

def initialize(name)
  @name = name.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/reaction/type.rb', line 5

def name
  @name
end

Class Method Details

.to_type_symbolObject

This isn’t perfect but works well enough.



43
44
45
46
47
48
49
50
# File 'lib/reaction/type.rb', line 43

def self.to_type_symbol
  ret = self.to_s
  ret.gsub!(/([A-Z]+)([A-Z])/, '\1_\2')
  ret.gsub!(/([a-z])([A-Z])/, '\1_\2')
  ret.downcase!
  ret.gsub!(/_type$/, '')
  ret.to_sym
end

Instance Method Details

#cleanupObject

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.



39
40
# File 'lib/reaction/type.rb', line 39

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.



29
30
31
# File 'lib/reaction/type.rb', line 29

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.



19
20
# File 'lib/reaction/type.rb', line 19

def validate_each(record, attribute, value)
end