module Opal::UseGem
Public Instance Methods
use_gem(gem_name, include_dependencies = true)
click to toggle source
Adds the “require_paths” (usually ‘lib/`) of gem with the given name to Opal
paths. By default will include the “require_paths” from all the dependent gems.
@param gem_name [String] the name of the gem @param include_dependencies [Boolean] whether or not to add recursively
the gem's dependencies
@raise [Opal::GemNotFound]
if gem or any of its runtime dependencies not found
# File lib/opal/paths.rb, line 57 def use_gem(gem_name, include_dependencies = true) append_paths(*require_paths_for_gem(gem_name, include_dependencies)) end
Private Instance Methods
require_paths_for_gem(gem_name, include_dependencies)
click to toggle source
# File lib/opal/paths.rb, line 63 def require_paths_for_gem(gem_name, include_dependencies) paths = [] spec = Gem::Specification.find_by_name(gem_name) raise GemNotFound, gem_name unless spec if include_dependencies spec.runtime_dependencies.each do |dependency| paths += require_paths_for_gem(dependency.name, include_dependencies) end end gem_dir = spec.gem_dir spec.require_paths.map do |path| paths << File.join(gem_dir, path) end paths end