Search code examples
rubyrubygemsactivesupport

Is it considered a good practice to use ActiveSupport in non-Rails gems?


I developed code as a part of big Rails project. Now I want to extract it as a separate script, independent of Rails to share with the community.

It's my first gem, and it might be overkill including Active Support to use the date functions and inflections as part of a relatively small gem.

What would be the best solution to this?


Solution

  • This is a really subjective call. While ActiveSupport does provide a number of useful date manipulation methods, including it just for that is extremely heavy-duty and can cause absolute chaos when included in projects that aren't expecting it. Some features, if enabled, like the auto-loader system, can change how require works and how missing classes are handled, in dramatic and unexpected ways.

    If you're creating a project that's probably going to be paired with Rails or ActiveSupport anyway, it's probably not a big deal. If this is rarely going to be the case, you might want to simply re-implement the date methods in your own module so that there's no dependency.

    Keep in mind that ActiveSupport does significant re-decorating to many core classes, so imposing that on people using your gem is perhaps making your gem a rather unruly guest.

    There's also few things more annoying than getting stuck in dependency hell where one won't work with ActiveSupport newer than X and another won't work with a version as old as that, meaning there's no singular version that works at all.