Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions contracts/support/pluralizer/inflector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pluralizer

type Inflector interface {
Language() Language
Plural(word string) string
SetLanguage(language Language) Inflector
Singular(word string) string
}
26 changes: 26 additions & 0 deletions contracts/support/pluralizer/language.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package pluralizer

type Language interface {
Name() string
SingularRuleset() Ruleset
PluralRuleset() Ruleset
}

type Transformation interface {
Apply(word string) string
}

type Pattern interface {
Matches(word string) bool
}

type Substitution interface {
From() string
To() string
}

type Transformations []Transformation

type Patterns []Pattern

type Substitutions []Substitution
9 changes: 9 additions & 0 deletions contracts/support/pluralizer/rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pluralizer

type Ruleset interface {
AddIrregular(substitutions ...Substitution) Ruleset
AddUninflected(words ...string) Ruleset
Regular() Transformations
Uninflected() Patterns
Irregular() Substitutions
}
5 changes: 5 additions & 0 deletions errors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ var (
PackageRegistrationDuplicate = New("'%s' had been registered")
PackageRegistrationNotFound = New("'%s' not found, cannot insert before it")

PluralizerLanguageNotFound = New("language %s not found").SetModule(ModulePluralizer)
PluralizerEmptyLanguageName = New("language name cannot be empty").SetModule(ModulePluralizer)
PluralizerNoSubstitutionsGiven = New("no substitutions provided").SetModule(ModulePluralizer)
PluralizerNoWordsGiven = New("no words provided").SetModule(ModulePluralizer)
Comment on lines +141 to +142
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should throw an error in these two cases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


QueueDriverFailedToPop = New("failed to pop job from %s queue: %v")
QueueDriverInvalid = New("%s doesn't implement contracts/queue/driver")
QueueDriverNoJobFound = New("no job found in %s queue")
Expand Down
1 change: 1 addition & 0 deletions errors/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
ModuleMigration = "migration"
ModuleOrm = "orm"
ModulePackages = "packages"
ModulePluralizer = "pluralizer"
ModuleQueue = "queue"
ModuleRoute = "route"
ModuleSchema = "schema"
Expand Down
222 changes: 222 additions & 0 deletions mocks/support/pluralizer/Inflector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading