tig
tig

Reputation: 27850

Should I choose gem dependencies by OS platform?

I am creating a gem, and it will use the rbappscript gem for additional functionality on Mac OS X.

Forcing users of other platforms to install that dependency is not a very good idea, and I'm not even sure if it will install at all. So, is it possible to customize which gems to depend on based on platform, and will not this create problems?

Upvotes: 2

Views: 192

Answers (2)

Bill Dueber
Bill Dueber

Reputation: 2706

You can use the RUBY_PLATFORM constant where you're declaring dependencies

# only on OSX
if  RUBY_PLATFORM =~ /darwin/i
  gem 'rbappscript'
end

# Only JRUBY
if defined? JRUBY_VERSION
  gem 'something_for_jruby'
end

Upvotes: 1

Fábio Batista
Fábio Batista

Reputation: 25290

If it's optional, it's not a dependency. Just don't declare it as such.

Add to your documentation a note, informing that if rbappscript is detected, additional functionality is available.

Then, in your code, you just check for the availability of the library. Even if your user is running on a Mac, (s)he can choose not to load this functionality for any given reason - predictable behavior on multiple platforms, for instance.

Upvotes: 4

Related Questions