Skip to content

Commit c02b864

Browse files
committed
Add support for ruby
1 parent 8413e8a commit c02b864

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/generator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ impl Generator<'_> {
167167
(None, "cs" | "java" | "kt") => "Summary".to_owned(),
168168
(None, "ts") => "index".to_owned(),
169169
(None, "go") => "models".to_owned(),
170+
(None, "rb") => "svix".to_owned(),
170171
(None, _) => "summary".to_owned(),
171172
};
172173

src/postprocessing.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl Postprocessor {
2525
"cs" => PostprocessorLanguage::CSharp,
2626
"java" => PostprocessorLanguage::Java,
2727
"ts" => PostprocessorLanguage::TypeScript,
28+
"rb" => PostprocessorLanguage::Ruby,
2829
_ => {
2930
tracing::warn!("no known postprocessing command(s) for {ext} files");
3031
PostprocessorLanguage::Unknown
@@ -43,7 +44,8 @@ impl Postprocessor {
4344
}
4445
}
4546
// pass output dir to postprocessor
46-
PostprocessorLanguage::Python
47+
PostprocessorLanguage::Ruby
48+
| PostprocessorLanguage::Python
4749
| PostprocessorLanguage::Go
4850
| PostprocessorLanguage::Kotlin
4951
| PostprocessorLanguage::CSharp
@@ -70,6 +72,7 @@ pub(crate) enum PostprocessorLanguage {
7072
CSharp,
7173
Java,
7274
TypeScript,
75+
Ruby,
7376
Unknown,
7477
}
7578

@@ -131,6 +134,8 @@ impl PostprocessorLanguage {
131134
],
132135
),
133136
],
137+
// https://github.com/fables-tales/rubyfmt
138+
Self::Ruby => &[("rubyfmt", &["-i", "--include-gitignored", "--fail-fast"])],
134139
}
135140
}
136141
}

src/template.rs

+15
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub(crate) fn env(tpl_dir: &Utf8Path) -> Result<minijinja::Environment<'static>,
6565
}
6666
"rust" | "csharp" => "///",
6767
"go" => "//",
68+
"ruby" => "#",
6869
_ => {
6970
return Err(minijinja::Error::new(
7071
minijinja::ErrorKind::UndefinedError,
@@ -126,6 +127,20 @@ pub(crate) fn env(tpl_dir: &Utf8Path) -> Result<minijinja::Environment<'static>,
126127
Ok(path_str)
127128
},
128129
);
130+
env.add_filter(
131+
"generate_ruby_path_str",
132+
|s: Cow<'_, str>, path_params: &Vec<Value>| -> Result<String, minijinja::Error> {
133+
let mut path_str = s.to_string();
134+
for field in path_params {
135+
let field = field.as_str().expect("Expected this to be a string");
136+
path_str = path_str.replace(
137+
&format!("{{{field}}}"),
138+
&format!("#{{{}}}", field.to_snake_case()),
139+
);
140+
}
141+
Ok(path_str)
142+
},
143+
);
129144

130145
Ok(env)
131146
}

src/types.rs

+14
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,16 @@ impl FieldType {
770770
}
771771
}
772772
}
773+
774+
fn to_ruby_typename(&self) -> Cow<'_, str> {
775+
match self {
776+
FieldType::SchemaRef(name) => name.clone().into(),
777+
FieldType::StringConst(_) => {
778+
unreachable!("FieldType::const should never be exposed to template code")
779+
}
780+
_ => panic!("types? in ruby?!?!, not on my watch!"),
781+
}
782+
}
773783
}
774784

775785
impl minijinja::value::Object for FieldType {
@@ -812,6 +822,10 @@ impl minijinja::value::Object for FieldType {
812822
ensure_no_args(args, "to_java")?;
813823
Ok(self.to_java_typename().into())
814824
}
825+
"to_ruby" => {
826+
ensure_no_args(args, "to_ruby")?;
827+
Ok(self.to_ruby_typename().into())
828+
}
815829

816830
"is_datetime" => {
817831
ensure_no_args(args, "is_datetime")?;

0 commit comments

Comments
 (0)