|
2 | 2 | ConvenienceRenderer, |
3 | 3 | type ForbiddenWordsInfo, |
4 | 4 | } from "../../ConvenienceRenderer.js"; |
| 5 | +import { minMaxLengthForType } from "../../attributes/Constraints.js"; |
5 | 6 | import { type Name, Namer } from "../../Naming.js"; |
6 | 7 | import type { RenderContext } from "../../Renderer.js"; |
7 | 8 | import type { OptionValues } from "../../RendererOptions/index.js"; |
@@ -103,14 +104,24 @@ export class RubyRenderer extends ConvenienceRenderer { |
103 | 104 |
|
104 | 105 | private dryType(t: Type, isOptional = false): Sourcelike { |
105 | 106 | const optional = isOptional ? ".optional" : ""; |
| 107 | + const length = (type: Type): string => { |
| 108 | + const [min, max] = minMaxLengthForType(type) ?? []; |
| 109 | + const constraints = [ |
| 110 | + min === undefined ? undefined : `min_size: ${min}`, |
| 111 | + max === undefined ? undefined : `max_size: ${max}`, |
| 112 | + ].filter((x): x is string => x !== undefined); |
| 113 | + return constraints.length === 0 |
| 114 | + ? "" |
| 115 | + : `.constrained(${constraints.join(", ")})`; |
| 116 | + }; |
106 | 117 | return matchType<Sourcelike>( |
107 | 118 | t, |
108 | 119 | (_anyType) => ["Types::Any", optional], |
109 | 120 | (_nullType) => ["Types::Nil", optional], |
110 | 121 | (_boolType) => ["Types::Bool", optional], |
111 | 122 | (_integerType) => ["Types::Integer", optional], |
112 | 123 | (_doubleType) => ["Types::Double", optional], |
113 | | - (_stringType) => ["Types::String", optional], |
| 124 | + (stringType) => ["Types::String", length(stringType), optional], |
114 | 125 | (arrayType) => [ |
115 | 126 | "Types.Array(", |
116 | 127 | this.dryType(arrayType.items), |
|
0 commit comments