Class: DependencyResolver
Overview
:nodoc:
Defined Under Namespace
Classes: UnableToResolveError
Instance Method Summary collapse
- #difference_in_loaded_features ⇒ Object
-
#initialize(name, version) ⇒ DependencyResolver
constructor
A new instance of DependencyResolver.
- #require! ⇒ Object
Constructor Details
#initialize(name, version) ⇒ DependencyResolver
Returns a new instance of DependencyResolver.
10 11 12 |
# File 'lib/rucola/dependencies/resolver.rb', line 10 def initialize(name, version) @name, @version = name, version end |
Instance Method Details
#difference_in_loaded_features ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rucola/dependencies/resolver.rb', line 36 def difference_in_loaded_features # save this to set it back to what it originally was loaded_features_before_rubygems = $LOADED_FEATURES.dup $LOADED_FEATURES.replace([]) require 'rubygems' rescue LoadError Kernel.module_eval do alias_method :__require_before_dependency_resolver, :require def require(name) unless Rucola::Dependencies.exclude?(name) __require_before_dependency_resolver(name) end end end # save this so we can compare what else was added except for rubygems loaded_features_before = $LOADED_FEATURES.dup require! result = ($LOADED_FEATURES - loaded_features_before) $LOADED_FEATURES.replace(loaded_features_before_rubygems) result end |
#require! ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rucola/dependencies/resolver.rb', line 14 def require! verbose_before = $VERBOSE $VERBOSE = nil begin if Kernel.private_methods.include? 'gem_original_require' gem_original_require(@name) else require(@name) end rescue LoadError # unfortunately, rubygems will always require 'etc.bundle' & 'fileutils' so there's no real way of knowing # wether or not it was required by rubygems or the actual library. begin Gem.activate(@name, true, @version) require(@name) rescue NameError raise UnableToResolveError, "Unable to resolve: '#{@name}', '#{@version}'" end end $VERBOSE = verbose_before end |