Andrew Grimm
Andrew Grimm

Reputation: 81530

Enforcing valid filenames within Rails application codebase

How can I enforce that filenames within a Rails application are valid? For example, not allowing a filename of app/models/.rb, or something with config/my_configuration.yml (with a space after "yml")?

Upvotes: 0

Views: 65

Answers (1)

vmarquet
vmarquet

Reputation: 2532

I think the best way is to prevent these files from appearing in your revision control system.

For example, if you use git, take a look at git hooks (and especially at git pre-commit hooks, since you want the verification that the filename is correct to be made before validating the commit). I think you can write validations based on regular expressions that will abort the commit if the validations fail.

You can write hooks in Ruby, for example check here.

Upvotes: 2

Related Questions