Best options for deploying standalone Ruby script and dependencies?
for a standalone Ruby script that Rails like deployment functions like Gemfile / "bundle install" etc.
which assumes that you are developing a Ruby script that you want to test and then deploy and maybe send to other users that Rails, for example, uses a deployment approach like:
a) GEM - marking GEM requirements and installing them as needed - for example Rails "Gemfile" where you mark what gems you need and then "install package" to install them
b) File Require - Automatically download * .rb files if they are in your script directory (I'm thinking of Rails, where if you put a class file in your applications / models directory, Rails will automatically download / require the file for you)
source to share
In my humble opinion, a gem is the way to go. Bundler makes things easier; it runs the skeleton for you when you run the command ...
bundle gem <GEM_NAME>
Take a look . As long as you list your dependencies in your gem file .gemspec
and someone installs your packaged gem (they don't need the package, just the RubyGems command gem
), the dependencies will be installed as gems along with it.
source to share
depends on whether it will be the tool that you expect people to use on every node it finds it on or not. also depends on whether the tool can be used in conjunction with public repositories.
if it just should work without worrying that you've already installed gems via satellite, you can use something like the following from your standalone script to install gems if not already present (remember systems against ruby user):
#!/usr/bin/env ruby
require 'rubygems'
def install_gem(name, version=Gem::Requirement.default)
begin
gem name, version
rescue LoadError
print "ruby gem '#{name}' not found, " <<
"would you like to install it (y/N)? : "
answer = gets
if answer[0].downcase.include? "y"
Gem.install name, version
else
exit(1)
end
end
end
# any of the following will work...
install_gem 'activesupport'
install_gem 'activesupport', '= 4.2.5'
install_gem 'activesupport', '~> 4.2.5'
require 'active_support/all'
...
source to share