class Stibium::Bundled::Bundle
Describe a bundle.
Attributes
@return [Config]
@return [Directory]
@return [Pathname]
Public Class Methods
@param path [String, Pathname] @param env [Hash{String => String}] @param ruby_config [Hash{Symbol => Object}]
@raise [Errno::ENOENT] @raise [ArgumentError] when given “path“ is not a directory.
# File lib/stibium/bundled/bundle.rb, line 36 def initialize(path, env: ENV.to_h, ruby_config: {}) self.tap do (@path = Pathname.new(path).realpath.freeze).tap do |base_path| raise ArgumentError, 'path is not a directory' unless base_path.directory? end @config = Config.new(self.path, env: env).freeze @directory = Directory.new(self.bundle_path, ruby_config: ruby_config).freeze end.freeze end
Public Instance Methods
Denote bundle seems installed by bundler.
@return [Boolean]
# File lib/stibium/bundled/bundle.rb, line 80 def bundled? locked? or standalone? end
Get path to gemfile.
@see gemfiles
@return [Pathname, nil]
# File lib/stibium/bundled/bundle.rb, line 89 def gemfile gemfiles&.fetch(0, nil) end
Get gemfile files (gemfile + lockfile) or nothing.
@note Files are returned in pairs, gemfile and its lockfile. As a result a missing file provides empty result.
@return [Array<Pathname>, nil]
# File lib/stibium/bundled/bundle.rb, line 98 def gemfiles [%w[gems.rb gems.locked], %w[Gemfile Gemfile.lock]].map do |m| m.map { |fname| path.join(fname) }.keep_if(&:file?) end.reject(&:empty?).reject { |r| r.size < 2 }.first end
Denote install seems to be happened (since specifications are present).
@return [Boolean]
# File lib/stibium/bundled/bundle.rb, line 73 def installed? !directory.specifications.empty? end
Denote lockfile (“gems.locked“ or “Gemfile.lock“) is present.
@see gemfiles
@return [Boolean]
# File lib/stibium/bundled/bundle.rb, line 57 def locked? !!gemfiles&.fetch(1, nil) end
Get specifications.
@see docs.ruby-lang.org/en/3.0.0/Gem/Specification.html
@return [Array<Gem::Specification>]
# File lib/stibium/bundled/bundle.rb, line 66 def specifications directory.specifications.map { |file| instance_eval(file.read, file.to_path) }.sort_by(&:name) end
Denote bundle seems to be installed as a standalone.
@see bundler.io/man/bundle-install.1.html
@return [Boolean]
# File lib/stibium/bundled/bundle.rb, line 109 def standalone? bundler_setup.yield_self { |fp| fp.file? and fp.readable? } end
@return [String]
# File lib/stibium/bundled/bundle.rb, line 48 def to_path path.to_path end
Protected Instance Methods
@return [Pathname]
# File lib/stibium/bundled/bundle.rb, line 155 def bundle_path Pathname.new(config.fetch('BUNDLE_PATH')).yield_self do |bundle_path| (bundle_path.absolute? ? bundle_path : path.join(bundle_path)) end end
Standalone setup file.
“bundle install –standalone?
@see standalone!
@see bundler.io/v2.2/man/bundle-install.1.html#OPTIONS
@return [Pathname]
# File lib/stibium/bundled/bundle.rb, line 174 def bundler_setup bundle_path.join('bundler/setup.rb') end
Load standalone setup if present, else fallback to bundler/setup
.
Load Bundler's setup (bundler/setup
) when all guards are “true“, as a result, default behavior, is to load bundler/setup
only when locked and installed.
@param guards [Array<Symbol>]
@return [self]
@raise [LoadError] when bundle/setup
is loaded and bundler is not present.
@see bundler.io/v1.5/bundler_setup.html @see github.com/ruby/ruby/blob/0e40cc9b194a5e46024d32b85a61e651372a65cb/lib/bundler.rb#L139 @see github.com/ruby/ruby/blob/0e40cc9b194a5e46024d32b85a61e651372a65cb/lib/bundler/setup.rb @see github.com/ruby/ruby/blob/69ed64949b0c02d4b195809fa104ff23dd100093/lib/bundler.rb#L11 @see github.com/ruby/ruby/blob/69ed64949b0c02d4b195809fa104ff23dd100093/lib/bundler/rubygems_integration.rb
# File lib/stibium/bundled/bundle.rb, line 146 def setup(guards: [:bundled, :installed]) self.tap do unless guards.map { |s| self.public_send('%s?' % s.to_s.gsub(/\?$/, '')) }.include?(false) standalone! { require 'bundler/setup' } end end end
Load standalone setup if present.
@return [self]
@raise [Errno::ENOENT, LoadError]
# File lib/stibium/bundled/bundle.rb, line 120 def standalone!(&fallback) # noinspection RubyResolve require(bundler_setup.realpath) rescue Errno::ENOENT, LoadError => e fallback ? fallback.call(self) : raise(e) ensure self end