0.0
No commit activity in last 3 years
No release in over 3 years
A rails gem providing naming methods for user models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 5.3, >= 5.0
 Project Readme

UserNaming

UserNaming is a simple gem that provides a 'name' column and some methods to standardize displaying user names in rails applications.

This isn't a big gem: it's a migration and a module with 4 or 5 methods that you include in your 'user' class. But, it lets me deal with user's names in the same way in every application I build. Over time, this pays off.

This gem currently supports rails 5 and beyond; adding 4.2 support is trivial, but would also require adding an appraisal configuration. Open for PRs if interested.

Installation

Add this line to your application's Gemfile and run bundle install to install it:

gem 'user_naming'

Then run the UserNaming install generator:

rails generate user_naming:install

If your user model is not User, you can (optionally) specify a user model with the --model flag. For example, if your user model class is Person:

rails generate user_naming:install --model Person

After you've run the install generator, apply the migration that was just generated:

rails db:migrate

The generator does the following:

  • Insert include UserNaming::User into your User model.
  • Create a migration to add a name column to your User table.

Usage

UserNaming supports setting the user's name as one field via name=.

Non-mutating accessors to read the user's name in different formats are provided:

  • name - the full name
  • first_name - always the first word of the name
  • middle name - everything that's not the first or last name
  • last_name - the last word of the name
  • initials - initials, joined without period or any other delimiter
  • first_name_last_initial - first name, last initial with a .

That's it!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tomichj/user_naming.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.