Method: Brine::ParameterTransforming#parameter_transformers
- Defined in:
- lib/brine/transforming.rb
#parameter_transformers ⇒ Object
Expose the chain of Transformers which will be used to convert parameters.
In the default implicit mode the list will be iterated over in sequence and the first Transformer which can handle the input will be used. The order of the Transformers is therefore significant: higher priority or more specific Transfomers should be earlier in the list than those that are lower priority or can handle a superset of supported input relative to those previous.
This exposed for direct list manipulation as an advanced customization point.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/brine/transforming.rb', line 85 def parameter_transformers @parameter_transformers ||= [ # These will be deprecated in preference for explicit type specification. Transformer.new('Double Quoted', /\A".*"\z/) {|input| input[1..-2] }, Transformer.new('Single Quoted', /\A'.*'\z/) {|input| input[1..-2] }, # Whitespace removal transforms # Handle stripping leading and trailing whitespace. # These are split out from the transforms to consolidate the behavior. # They call transform on the stripped value so that subsequent transforms no longer # have to deal with such whitespace. # # Note that these need to deal with multiline string arguments which require # the multiline flag and \A/\z anchors to properly operate on the full string rather than # being line oriented. The calls to +#strip+ are also not likely to properly clean up # multiline strings but is just meant as a (potentially ineffective) optimization over # recursive calls and capturing. Transformer.new('Trailing Whitespace', /\A\s+.*\z/) {|input| transformed_parameter(input.strip) }, Transformer.new('Leading Whitespace', /\A.*\s+\z/m) {|input| transformed_parameter(input.strip) }, # Template Expansion Transformer.new('Template', /.*{{.*}}.*/) {|input| as_template(input) }, # Scalars Transformer.new('Integer', /\A-?\d+\z/) {|input| input.to_i }, Transformer.new('Boolean', /\Atrue|false\z/) {|input| input.to_s == "true" }, # This presently does not support flags after the closing slash, support for these should be added as needed Transformer.new('Regex', /\A\/.*\/\z/) {|input| Regexp.new(input[1..-2]) }, Transformer.new('DateTime', /^#{DATE}T#{TIME}#{MILLIS}#{TZ}$/) {|input| Time.parse(input) }, # Structures Transformer.new('Array', /\A\[.*\]\z/m) {|input| JSON.parse(input) }, Transformer.new('Object', /\A{.*}\z$/m) {|input| JSON.parse(input) }, # String sentinel...this is last to act as a catch-all. Transformer.new('String', /.*/) {|input| input }, ] end |