B
B
Bogdan2018-03-30 12:19:14
Ruby on Rails
Bogdan, 2018-03-30 12:19:14

How to properly separate gems for different platforms?

Hello. Tell me please. I decided to transfer my project from a Windows server to Linux. And here is one gem, you need to install it like this under Windows:

gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git'

and under Lincus, like this, because if you specify git, it gives an error: If you specify 2 gems, then it gives an error
gem 'bcrypt'
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', platforms: [:mingw, :x64_mingw]
gem 'bcrypt', platforms: [:mri]

Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
oh_shi, 2018-03-30
@bogdan_uman

In the interpreter, look at the values ​​of the platforms of interest in the RUBY_PLATFORM constant.

if RUBY_PLATFORM =~ /x86_64-linux/
  gem 'bcrypt'
else
  gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git'
end

M
Marat Amerov, 2018-03-30
@amerov

platforms :mswin do
  gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git'
end

platforms  :ruby  do
  gem 'bcrypt'
end

OR
install_if -> { RUBY_PLATFORM =~ /linux/ } do
  gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git'
end

install_if -> { RUBY_PLATFORM =~ /mswin/ }
  gem 'bcryptcrypt'
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question