Module: Opal::Project::Collection

Included in:
Opal, Builder
Defined in:
opal/lib/opal/project.rb

Overview

A mixin for methods that are used to extend either global (Opal) or local (Opal::Builder instance) to contain a collection of projects.

Instance Method Summary collapse

Instance Method Details

#add_project(project) ⇒ Object



66
67
68
# File 'opal/lib/opal/project.rb', line 66

def add_project(project)
  projects << project
end

#all_projectsObject



46
47
48
49
50
51
52
# File 'opal/lib/opal/project.rb', line 46

def all_projects
  if self == Opal
    projects
  else
    Opal.projects + projects
  end
end

#has_project?(root_dir) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'opal/lib/opal/project.rb', line 58

def has_project?(root_dir)
  all_projects.any? { |i| i.root_dir == root_dir }
end

#project_of(root_dir) ⇒ Object



62
63
64
# File 'opal/lib/opal/project.rb', line 62

def project_of(root_dir)
  all_projects.find { |i| i.root_dir == root_dir }
end

#projectsObject



54
55
56
# File 'opal/lib/opal/project.rb', line 54

def projects
  @projects ||= []
end

#setup_project(file) ⇒ Object



70
71
72
# File 'opal/lib/opal/project.rb', line 70

def setup_project(file)
  Project.setup_project_for(self, file)
end

#use_gem(gem_name, include_dependencies = true) ⇒ Object

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.

Parameters:

  • gem_name (String)

    the name of the gem

  • include_dependencies (Boolean) (defaults to: true)

    whether or not to add recursively the gem's dependencies

Raises:



83
84
85
86
87
88
89
# File 'opal/lib/opal/project.rb', line 83

def use_gem(gem_name, include_dependencies = true)
  if RUBY_ENGINE == 'opal'
    warn "Opal: paths for gems are not available in JavaScript. The directive `use_gem #{gem_name}` has been ignored."
  else
    append_paths(*require_paths_for_gem(gem_name, include_dependencies))
  end
end