jeremyevans / sequel

Sequel: The Database Toolkit for Ruby
http://sequel.jeremyevans.net
Other
5k stars 1.07k forks source link

Inflector problem with word "status" #2254

Closed dux closed 3 days ago

dux commented 4 days ago

Complete Description of Issue

I cant make "status".singularize to return "status" and not "statu"

Problem is that it should stay the same, but built in rule found in Sequel.inflections.singulars, [/s$/i, ""] removes "s" and returns positive match here https://github.com/jeremyevans/sequel/blob/master/lib/sequel/model/inflections.rb#L138

How to fix this? And suggestion to add built in rule for status.

Simplest Possible Self-Contained Example Showing the Bug

ruby -e 'require "sequel"; Sequel.extension :inflector; Sequel.inflections { _1.singular /status$/, "status" }; puts "status".singularize'
ruby -e 'require "sequel"; Sequel.extension :inflector; puts "status".singularize'

"statu", not "status"

Full Backtrace of Exception (if any)

No response

SQL Log (if any)

No response

Ruby Version

3.2.2

Sequel Version

5.85

jeremyevans commented 3 days ago

status is singular (statuses is the plural form), and you should not be trying to singularize already singular names (singularization is not designed or expected to be idempotent).

You already showed the command to work around your issue (Sequel.inflections { _1.singular /status$/, "status" }).

Note that there are likely many actual cases where singularization of the plural form is not correct, due to irregularities in the English language. However, the current inflection rules are basically finalized. Users who need changes to them should configure the changes.