Search code examples
rubyrubygemsbundlebundlergemspecs

Is there a command to add gem to gemspec?


I know there is a command to add a gem to Gemfile: bundle add GEMNAME, but is there a similar command to add a dependency to gemspec?

Is there something like bundle add rails --gemspec? Is there a command that adds this line to gemspec?:

  spec.add_dependency 'GEMNAME', 'GEMVERSION'

Solution

  • I think the answer is "no". At least, not with the "standard" ruby tools; someone out there might have built a CLI for it, but I can't find one.


    I've barely ever used the bundle add command. For most use cases I expect it's only marginally faster than editing the Gemfile and running bundle, with the added downside that you need to remember this special command (and probably still check that it made the right change in the Gemfile!).

    Maybe it would be useful if I was adding the same dependency to a dozen projects or something, but that's not a "normal" task for me to do.

    Likewise, I can't really imagine a scenario where using a CLI to update a gemspec is really beneficial. Surely it's equally fast, if not faster, to just open the gemspec and edit it directly?

    That's why there's (as far as I can find?) no popular tool for automating this.


    On a side note, the command bundle gem <gemname> is very useful, when creating a new gem, because it automates a lot of boilerplate code to kickstart a new library, similar to running rails new <app-name>.