Module: Toys::StandardMixins::Gems
- Includes:
- Mixin
- Defined in:
- lib/toys/standard_mixins/gems.rb
Overview
Provides methods for installing and activating third-party gems. When
this mixin is included, it provides a gem
method that has the same
effect as Utils::Gems#activate, so you can ensure a gem is
present when running a tool. A gem
directive is likewise added to the
tool DSL itself, so you can also ensure a gem is present when defining a
tool.
Usage
Make these methods available to your tool by including this mixin in your tool:
include :gems
You can then call the mixin method #gem to ensure that a gem is installed and in the load path. For example:
tool "my_tool" do
include :gems
gem "nokogiri", "~> 1.15"
def run
# Do stuff with Nokogiri
end
end
If you pass additional options to the include directive, those are used to initialize settings for the gem install process. For example:
include :gems, on_missing: :error
See Utils::Gems#initialize for a list of supported options.
Instance Method Summary collapse
-
#gem(name, *requirements) ⇒ void
Activate the given gem.
-
#gems ⇒ Toys::Utils::Gems
A tool-wide instance of Utils::Gems.
Methods included from Mixin
Instance Method Details
#gem(name, *requirements) ⇒ void
This method returns an undefined value.
Activate the given gem. If it is not present, attempt to install it (or inform the user to update the bundle).
57 58 59 |
# File 'lib/toys/standard_mixins/gems.rb', line 57 def gem(name, *requirements) self.class.gems.activate(name, *requirements) end |
#gems ⇒ Toys::Utils::Gems
A tool-wide instance of Utils::Gems.
45 46 47 |
# File 'lib/toys/standard_mixins/gems.rb', line 45 def gems self.class.gems end |