module Stibium::Bundled

Sample of use:

“`ruby # file: lib/awesome_gem.rb module AwesomeGem

include(Stibium::Bundled)

self.bundled_from("#{__dir__}/..", setup: true)

end “`

Protected Class Methods

bundler() click to toggle source

@api private

@return [Proc]

# File lib/stibium/bundled.rb, line 103
def bundler
  lambda do |basedir, env:, ruby_config: nil|
    Bundle.new(basedir, env: env, ruby_config: ruby_config).yield_self do |bundle|
      bundle.bundled? ? bundle : nil
    end
  end
end
call(target, basedir:, env: ENV.to_h, ruby_config: nil) click to toggle source

@param target [Class, Module] @param basedir [String, Pathname] @param env [Hash{String => String}] @param ruby_config [Hash{Symbol => Object}]

@return [Class, Module] given “Class“ or “Module“

# File lib/stibium/bundled.rb, line 86
def call(target, basedir:, env: ENV.to_h, ruby_config: nil)
  target.tap do |t|
    t.singleton_class.tap do |sc|
      sc.singleton_class.__send__(:include, self)
      sc.define_method(:bundled?) { !bundled.nil? }
      sc.define_method(:bundled) do
        Stibium::Bundled.__send__(:bundler).call(basedir, env: env, ruby_config: ruby_config)
      end
    end
  end
end

Private Class Methods

included(othermod) click to toggle source

Callback invoked whenever the receiver is included in another module or class.

@param [Class, Module] othermod

@see ruby-doc.org/core-2.5.3/Module.html#method-i-included

# File lib/stibium/bundled.rb, line 39
def included(othermod)
  othermod.singleton_class.__send__(:include, self) unless othermod.singleton_class?
end

Public Instance Methods

bundled() click to toggle source

@return [Bundle, nil]

@see .call

# File lib/stibium/bundled.rb, line 56
def bundled
  nil
end
bundled?() click to toggle source

Denote bundle is locked or standalone.

@return [Boolean]

@see .call

# File lib/stibium/bundled.rb, line 49
def bundled?
  false
end

Protected Instance Methods

bundled_from(basedir, setup: false, env: ENV.to_h, ruby_config: {}) { |bundle| ... } click to toggle source

@param basedir [String, Pathname] @param setup [Boolean, Array<Symbol>] @param env [Hash{String => String}] @param ruby_config [Hash{Symbol => Object}]

@return [Bundle. nil]

@see Stibium::Bundled::Bundle#setup

# File lib/stibium/bundled.rb, line 70
def bundled_from(basedir, setup: false, env: ENV.to_h, ruby_config: {})
  # @type [Stibium::Bundled::Bundle] bundle
  Stibium::Bundled.call(self, basedir: basedir, env: env, ruby_config: ruby_config).bundled&.tap do |bundle|
    bundle.__send__(:setup, **{ guards: setup.is_a?(Array) ? setup : nil }.compact) if setup

    yield(bundle) if block_given?
  end
end