Sha256: 6146106643a0fe05bd2c17a51534f232472450f489b9f81c9ce3aec023d1838b

Contents?: true

Size: 1.39 KB

Versions: 8

Compression:

Stored size: 1.39 KB

Contents

module Opal
  def self.gem_dir
    File.expand_path('../..', __FILE__.untaint)
  end

  def self.core_dir
    File.expand_path('../../../opal', __FILE__.untaint)
  end

  def self.std_dir
    File.expand_path('../../../stdlib', __FILE__.untaint)
  end

  # Add a file path to opals load path. Any gem containing ruby code that Opal
  # has access to should add a load path through this method. Load paths added
  # here should only be paths which contain code targeted at being compiled by
  # Opal.
  def self.append_path(path)
    append_paths(path)
  end
  def self.append_paths(*paths)
    self.paths.concat(paths)
  end

  module UseGem
    def use_gem(gem_name, include_dependencies = true)
      append_paths(*require_paths_for_gem(gem_name, include_dependencies))
    end
    
    private

    def require_paths_for_gem(gem_name, include_dependencies)
      paths = []
      spec = Gem::Specification.find_by_name(gem_name)

      spec.runtime_dependencies.each do |dependency|
        paths += require_paths_for_gem(dependency.name, include_dependencies)
      end if include_dependencies

      gem_dir = spec.gem_dir
      spec.require_paths.map do |path|
        paths << File.join(gem_dir, path)
      end

      paths
    end
  end

  extend UseGem

  # Private, don't add to these directly (use .append_path instead).
  def self.paths
    @paths ||= [core_dir.untaint, std_dir.untaint, gem_dir.untaint]
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
opal-0.9.0.beta1 lib/opal/paths.rb
opal-0.8.1 lib/opal/paths.rb
opal-0.8.1.rc1 lib/opal/paths.rb
opal-wedge-0.9.0.dev lib/opal/paths.rb
opal-0.8.0 lib/opal/paths.rb
opal-0.8.0.rc3 lib/opal/paths.rb
opal-0.8.0.rc2 lib/opal/paths.rb
opal-0.8.0.rc1 lib/opal/paths.rb