Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Inflector #470

Closed
kazk opened this issue Mar 19, 2021 · 1 comment · Fixed by #471
Closed

Remove Inflector #470

kazk opened this issue Mar 19, 2021 · 1 comment · Fixed by #471
Assignees

Comments

@kazk
Copy link
Member

kazk commented Mar 19, 2021

Inflector is no longer maintained. It's a large dependency, and we don't use most of its features (just to_plural). We should be able to replace it with a much simpler function by not trying to handle the irregulars. Inflector is buggy anyway (see #467).

Here's a Rust port of a popular JavaScript package plur minus the irregular and case matching.

fn to_plural(word: &str) -> String {
    // Words ending in s, x, z, ch, sh will be pluralized with -es (eg. foxes).
    if word.ends_with('s')
        || word.ends_with('x')
        || word.ends_with('z')
        || word.ends_with("ch")
        || word.ends_with("sh")
    {
        return format!("{}es", word);
    }

    // Words ending in y that are preceded by a consonant will be pluralized by
    // replacing y with -ies (eg. puppies).
    if word.ends_with('y') {
        if let Some(c) = word.chars().nth(word.len() - 2) {
            if !matches!(c, 'a' | 'e' | 'i' | 'o' | 'u') {
                // Remove 'y' and add `ies`
                let mut chars = word.chars();
                chars.next_back();
                return format!("{}ies", chars.as_str());
            }
        }
    }

    // All other words will have "s" added to the end (eg. days).
    format!("{}s", word)
}

One concern is that this is not idempotent. (e.g., Endpoints. See #284 (comment)). We can special-case the native failures, and custom resource can specify irregular.


is_pascal_case is also used:
https://github.com/clux/kube-rs/blob/813da82a5924ca54829689eae9b88e2cef465494/kube/src/api/dynamic.rs#L171-L176

but I believe it should be removed. kube-derive side was removed 7187db7

@clux
Copy link
Member

clux commented Mar 19, 2021

I think a small helper to deal with this from a kube POV for now makes sense.
It lets us handle the special cases, and it'll give us a less heavy dependency, that's also probably better with its memory management: #14 (comment)

The pascal case helper doesn't do anything useful anymore so can just remove those lines.

@kazk kazk self-assigned this Mar 19, 2021
@kazk kazk mentioned this issue Mar 19, 2021
@clux clux closed this as completed in #471 Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants