Class: Inspec::DependencyLoader
- Inherits:
-
Object
- Object
- Inspec::DependencyLoader
- Defined in:
- lib/inspec/dependency_loader.rb
Instance Attribute Summary collapse
-
#gem_list ⇒ Object
Returns the value of attribute gem_list.
-
#gem_path ⇒ Object
Returns the value of attribute gem_path.
Class Method Summary collapse
Instance Method Summary collapse
- #gem_installed?(name) ⇒ Boolean
- #gem_version_installed?(name, version) ⇒ Boolean
-
#initialize(gem_path = nil, gem_list = []) ⇒ DependencyLoader
constructor
initializes the dependency_loader.
- #inspec_gem_path ⇒ Object
- #list_installed_gems ⇒ Object
-
#list_managed_gems ⇒ Array[Gem::Specification]
Lists all gems found in the inspec_gem_path.
- #load ⇒ Object
Constructor Details
#initialize(gem_path = nil, gem_list = []) ⇒ DependencyLoader
initializes the dependency_loader
10 11 12 13 |
# File 'lib/inspec/dependency_loader.rb', line 10 def initialize(gem_path = nil, gem_list = []) @gem_path = gem_path || inspec_gem_path @gem_list = gem_list end |
Instance Attribute Details
#gem_list ⇒ Object
Returns the value of attribute gem_list.
7 8 9 |
# File 'lib/inspec/dependency_loader.rb', line 7 def gem_list @gem_list end |
#gem_path ⇒ Object
Returns the value of attribute gem_path.
7 8 9 |
# File 'lib/inspec/dependency_loader.rb', line 7 def gem_path @gem_path end |
Class Method Details
.inspec_gem_path ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/inspec/dependency_loader.rb', line 29 def self.inspec_gem_path require "rbconfig" unless defined?(RbConfig) ruby_abi_version = RbConfig::CONFIG["ruby_version"] # TODO: why are we installing under the api directory for plugins? base_dir = Inspec.config_dir base_dir = File.realpath base_dir if File.exist? base_dir File.join(base_dir, "gems", ruby_abi_version) end |
Instance Method Details
#gem_installed?(name) ⇒ Boolean
48 49 50 |
# File 'lib/inspec/dependency_loader.rb', line 48 def gem_installed?(name) list_installed_gems.any? { |spec| spec.name == name } end |
#gem_version_installed?(name, version) ⇒ Boolean
52 53 54 55 56 57 58 |
# File 'lib/inspec/dependency_loader.rb', line 52 def gem_version_installed?(name, version) if version.nil? list_installed_gems.any? { |s| s.name == name } else list_installed_gems.any? { |s| s.name == name && Gem::Requirement.new(version.split(",")) =~ s.version } end end |
#inspec_gem_path ⇒ Object
25 26 27 |
# File 'lib/inspec/dependency_loader.rb', line 25 def inspec_gem_path self.class.inspec_gem_path end |
#list_installed_gems ⇒ Object
44 45 46 |
# File 'lib/inspec/dependency_loader.rb', line 44 def list_installed_gems list_managed_gems end |
#list_managed_gems ⇒ Array[Gem::Specification]
Lists all gems found in the inspec_gem_path.
40 41 42 |
# File 'lib/inspec/dependency_loader.rb', line 40 def list_managed_gems Dir.glob(File.join(gem_path, "specifications", "*.gemspec")).map { |p| Gem::Specification.load(p) } end |
#load ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/inspec/dependency_loader.rb', line 15 def load Gem.path << gem_path Gem.refresh gem_list.each do |gem_data| version = gem_data[:version].nil? ? "> 0" : gem_data[:version] activate_gem_dependency(gem_data[:name], version) end end |