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, 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.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/toys/utils/gems.rb', line 100 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).
75 76 77 |
# File 'lib/toys/utils/gems.rb', line 75 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).
128 129 130 131 132 133 134 135 136 |
# File 'lib/toys/utils/gems.rb', line 128 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.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/toys/utils/gems.rb', line 145 def bundle(groups: nil, search_dirs: nil) Gems.synchronize do gemfile_path = find_gemfile(Array(search_dirs)) activate("bundler", "~> 2.1") if configure_gemfile(gemfile_path) setup_bundle(gemfile_path, groups || []) end end end |