Class: Toys::Utils::Gems
- Inherits:
-
Object
- Object
- Toys::Utils::Gems
- Defined in:
- lib/toys/utils/gems.rb
Overview
A helper class that activates and installs gems and sets up bundler.
This class is not loaded by default. Before using it directly, you should
require "toys/utils/gems"
Defined Under Namespace
Classes: ActivationFailedError, AlreadyBundledError, BundleNotInstalledError, BundlerFailedError, GemfileNotFoundError, GemfileUpdateNeededError, IncompatibleToysError, InstallFailedError
Class Method Summary collapse
-
.activate(name, *requirements) ⇒ void
Activate the given gem.
Instance Method Summary collapse
-
#activate(name, *requirements) ⇒ void
Activate the given gem.
-
#bundle(groups: nil, search_dirs: nil) ⇒ void
Set up the bundle.
-
#initialize(on_missing: nil, on_conflict: nil, terminal: nil, input: nil, output: nil, suppress_confirm: nil, default_confirm: nil) ⇒ Gems
constructor
Create a new gem activator.
Constructor Details
#initialize(on_missing: nil, on_conflict: nil, terminal: nil, input: nil, output: nil, suppress_confirm: nil, default_confirm: nil) ⇒ Gems
Create a new gem activator.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/toys/utils/gems.rb', line 113 def initialize(on_missing: nil, on_conflict: nil, terminal: nil, input: nil, output: nil, suppress_confirm: nil, default_confirm: nil) @default_confirm = default_confirm || default_confirm.nil? ? true : false @on_missing = on_missing || if suppress_confirm @default_confirm ? :install : :error else :confirm end @on_conflict = on_conflict || :error @terminal = terminal @input = input || ::STDIN @output = output || ::STDOUT end |
Class Method Details
.activate(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).
82 83 84 |
# File 'lib/toys/utils/gems.rb', line 82 def self.activate(name, *requirements) new.activate(name, *requirements) end |
Instance Method Details
#activate(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).
141 142 143 144 145 146 147 148 149 |
# File 'lib/toys/utils/gems.rb', line 141 def activate(name, *requirements) Gems.synchronize do begin gem(name, *requirements) rescue ::Gem::LoadError => e handle_activation_error(e, name, requirements) end end end |
#bundle(groups: nil, search_dirs: nil) ⇒ void
This method returns an undefined value.
Set up the bundle.
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/toys/utils/gems.rb', line 158 def bundle(groups: nil, search_dirs: nil) Gems.synchronize do gemfile_path = find_gemfile(Array(search_dirs)) if configure_gemfile(gemfile_path) activate("bundler", "~> 2.1") require "bundler" setup_bundle(gemfile_path, groups || []) end end end |