module PluralizeHelper

Like the name suggests, helper methods for pluralization.

Constants

ENFORCE_PLURALS

Public Instance Methods

enforce_plural(word) click to toggle source

If ENFORCE_PLURALS is true (default == true) This enforces plural names for all collections and returns 403 otherwise.

word

collection name

# File lib/doppelserver/routes/helpers/pluralize_helper.rb, line 25
def enforce_plural(word)
  # Mixing in the contol exclusion is strange here.
  # This can still coexist with a /controls endpoint but may be confusing.
  # I don't want to think about the possibility that we don't have plural
  # collections and happen to have a collision with a control collection yet.
  if word != 'control' && ENFORCE_PLURALS && singular?(word)
    halt 403, 'only plural collection names allowed'
  end
  word
end
singular?(word) click to toggle source

Determines if

word

an input word

is singular. Retutns truthy.

# File lib/doppelserver/routes/helpers/pluralize_helper.rb, line 15
def singular?(word)
  ActiveSupport::Inflector.singularize(word) == word
end