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
-
.call(target, basedir:, env: ENV.to_h, ruby_config: {}) ⇒ Class, Module
Given
ClassorModule. -
.included(othermod) ⇒ Object
private
Callback invoked whenever the receiver is included in another module or class.
Instance Method Summary collapse
- #bundled ⇒ Bundle?
-
#bundled? ⇒ Boolean
Denote bundle is locked or standalone.
- #bundled_from(basedir, setup: false, env: ENV.to_h, ruby_config: {}) ⇒ Bundle. nil protected
Class Method Details
.call(target, basedir:, env: ENV.to_h, ruby_config: {}) ⇒ Class, Module
Returns 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.
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
#bundled? ⇒ Boolean
Denote bundle is locked or standalone.
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)
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 |