Module: BundlerSkills::RubygemsHook
- Defined in:
- lib/bundler_skills/rubygems_hook.rb
Overview
Entry point for the RubyGems ‘Gem.post_install` hook (registered in lib/rubygems_plugin.rb). Fires once per gem actually installed during a `bundle install` / `bundle update`, and syncs THAT gem’s skills only.
Like the old Bundler hook, it holds no real logic: it guards on context and the disable switch, then delegates to Synchronizer#sync_gem. Any error is swallowed as a warning so it never aborts the user’s install.
Class Method Summary collapse
-
.bundle_context? ⇒ Boolean
Only act inside a ‘bundle install` for a project with a Gemfile.
- .install(installer) ⇒ Object
- .safe_name(installer) ⇒ Object
- .warn(message) ⇒ Object
Class Method Details
.bundle_context? ⇒ Boolean
Only act inside a ‘bundle install` for a project with a Gemfile. This keeps a plain `gem install foo` (no project context) from creating symlinks in whatever directory the user happens to be in.
28 29 30 31 32 33 34 35 |
# File 'lib/bundler_skills/rubygems_hook.rb', line 28 def bundle_context? return false unless defined?(Bundler) root = Bundler.root root.join("Gemfile").file? || root.join("gems.rb").file? rescue StandardError false end |
.install(installer) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/bundler_skills/rubygems_hook.rb', line 15 def install(installer) spec = installer.spec return unless bundle_context? return if Disabling.disabled? Synchronizer.new(config: Config.load).sync_gem(spec) rescue StandardError => e warn("[bundler-skills] skipped #{safe_name(installer)}: #{e.class}: #{e.}") end |
.safe_name(installer) ⇒ Object
37 38 39 40 41 |
# File 'lib/bundler_skills/rubygems_hook.rb', line 37 def safe_name(installer) installer.spec.name rescue StandardError "(unknown gem)" end |
.warn(message) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/bundler_skills/rubygems_hook.rb', line 43 def warn() if defined?(Bundler) Bundler.ui.warn() else Kernel.warn() end end |