Module: Stibium::Bundled

Defined in:
lib/stibium/bundled.rb

Overview

Sample of use:

# file: lib/awesome_gem.rb
module AwesomeGem
  include(Stibium::Bundled)

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

Defined Under Namespace

Classes: Bundle

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(target, basedir:, env: ENV.to_h, ruby_config: {}) ⇒ Class, Module

Returns given Class or Module.

Parameters:

  • target (Class, Module)
  • basedir (String, Pathname)
  • env (Hash{String => String}) (defaults to: ENV.to_h)
  • ruby_config (Hash{Symbol => Object}) (defaults to: {})

Returns:

  • (Class, Module)

    given Class or Module



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/stibium/bundled.rb', line 88

def call(target, basedir:, env: ENV.to_h, ruby_config: {})
  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
        # @type [Bundle] bundle
        Bundle.new(basedir, env: env, ruby_config: ruby_config)
              .yield_self { |bundle| bundle.bundled? ? bundle : nil }
      end
    end
  end
end

.included(othermod) ⇒ Object (private)

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

Parameters:

  • othermod (Class, Module)

See Also:



39
40
41
# File 'lib/stibium/bundled.rb', line 39

def included(othermod)
  othermod.singleton_class.__send__(:include, self) unless othermod.singleton_class?
end

Instance Method Details

#bundledBundle?

Returns:

See Also:



56
57
58
# File 'lib/stibium/bundled.rb', line 56

def bundled
  nil
end

#bundled?Boolean

Denote bundle is locked or standalone.

Returns:

  • (Boolean)

See Also:



49
50
51
# File 'lib/stibium/bundled.rb', line 49

def bundled?
  false
end

#bundled_from(basedir, setup: false, env: ENV.to_h, ruby_config: {}) ⇒ Bundle. nil (protected)

Parameters:

  • basedir (String, Pathname)
  • setup (Boolean, Array<Symbol>) (defaults to: false)
  • env (Hash{String => String}) (defaults to: ENV.to_h)
  • ruby_config (Hash{Symbol => Object}) (defaults to: {})

Returns:

See Also:



70
71
72
73
74
75
76
77
78
79
# 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|
    unless bundle.nil?
      bundle.__send__(:setup, **(setup.is_a?(Array) ? { guards: setup } : {})) if setup

      yield(bundle) if block_given?
    end
  end
end