riboseinc / uri_format_validator

Validate URL for Rails
MIT License
3 stars 2 forks source link

Decide on validator name #46

Closed skalee closed 6 years ago

skalee commented 6 years ago

This one has nothing to do with gem name.

At the moment, the validator is named UriFormatValidator (exactly like the gem itself). Hence, models which use this validator look as follows:

class Post
  # …
  validates :author_url, uri_format: {validation: :options}
end

The current state is bit unintended, and is a result of my mistake while renaming the gem. Previously it was named UrlValidator and was used as follows:

class Post
  # …
  validates :author_url, url: {validation: :options}
end

And perhaps we should name it UriValidator:

class Post
  # …
  validates :author_url, uri: {validation: :options}
end

I am thinking which one is better: UriFormatValidator or UriValidator.

The former is: – More descriptive – IMHO seems to match names of standard Rails validators bit better (I am thinking about FormatValidator, precisely – Less likely to collide with similar gems, as the validator name exactly matches the gem name. Yes, there are several gems with similar purpose and naming. And yes, it can happen that two or more gems of similar purpose are in the single project, typically when one comes as a dependency of yet another gem.

The latter is: – Shorter, memorable, and more convenient, which is always a good thing – Validator name collision is still quite unlikely, and if happen, it can be fixed by specifying a fully qualified name of the validator (validates :author_url, "UriFormatValidator::UriValidator" => {…})

Change is pretty simple to do, if wanted. Your decision, @ronaldtse.

skalee commented 6 years ago

@kwkwan You're welcome to leave your comments as well, I have a feeling that you're one of the primary users of this gem.

ronaldtse commented 6 years ago

@skalee I agree we could use a shorter version of :uri. It would be quite unlikely that people would use two of these gems with conflicting names anyway.

ronaldtse commented 6 years ago

If this is agreed we can go ahead. Thanks @skalee !