Class: Opal::Project
- Inherits:
-
Object
- Object
- Opal::Project
- Defined in:
- opal/lib/opal/project.rb
Overview
Opal::Project is a representation of an Opal project. In particular it's a directory containing Ruby files which is described by Opalfile.
Defined Under Namespace
Modules: Collection Classes: Opalfile
Constant Summary collapse
- PROJECT_DEFINING_FILES =
%w[Opalfile Gemfile *.gemspec].freeze
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
Class Method Summary collapse
- .dir_is_project_candidate?(current_dir) ⇒ Boolean
-
.locate_root_dir(file) ⇒ String?
Finds the project's root directory by searching for a project-defining file in the given file's ancestor directories.
- .setup_project_for(collection, file) ⇒ Object
Instance Method Summary collapse
- #has_opalfile? ⇒ Boolean
-
#initialize(root_dir, collection) ⇒ Project
constructor
A new instance of Project.
- #parse_opalfile ⇒ Object
Constructor Details
#initialize(root_dir, collection) ⇒ Project
Returns a new instance of Project.
126 127 128 129 130 131 132 133 |
# File 'opal/lib/opal/project.rb', line 126 def initialize(root_dir, collection) @root_dir = root_dir @collection = collection collection.add_project(self) parse_opalfile end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
135 136 137 |
# File 'opal/lib/opal/project.rb', line 135 def collection @collection end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
135 136 137 |
# File 'opal/lib/opal/project.rb', line 135 def root_dir @root_dir end |
Class Method Details
.dir_is_project_candidate?(current_dir) ⇒ Boolean
202 203 204 205 |
# File 'opal/lib/opal/project.rb', line 202 def self.dir_is_project_candidate?(current_dir) @glob_cache[current_dir] ||= Dir[File.join(current_dir, "{#{PROJECT_DEFINING_FILES.join(',')}}")] @glob_cache[current_dir].any? end |
.locate_root_dir(file) ⇒ String?
Finds the project's root directory by searching for a project-defining file in the given file's ancestor directories.
A project-defining file is one of the files in the PROJECT_DEFINING_FILES constant.
the file does not exist.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'opal/lib/opal/project.rb', line 172 def self.locate_root_dir(file) begin file = File.realpath(file) rescue Errno::ENOENT return nil end current_dir = file until dir_is_project_candidate? current_dir parent_dir = File.dirname(current_dir) # If no further parent, stop the search. # In addition, stop progressing if we hit a directory called "vendor". # This is a special case - some users are installing gem dependencies # inside a vendor directory in a standalone project. We don't want both # to be conflated, as then the gem's load paths may not be registered. break if current_dir == parent_dir || File.basename(current_dir) == 'vendor' current_dir = parent_dir end if dir_is_project_candidate? current_dir current_dir end end |
.setup_project_for(collection, file) ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'opal/lib/opal/project.rb', line 154 def self.setup_project_for(collection, file) root_dir = locate_root_dir(file) return collection.project_of(root_dir) if collection.has_project?(root_dir) return nil unless root_dir return nil if @loading.include? root_dir Project.new(root_dir, collection) end |
Instance Method Details
#has_opalfile? ⇒ Boolean
137 138 139 |
# File 'opal/lib/opal/project.rb', line 137 def has_opalfile? @has_opalfile end |
#parse_opalfile ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'opal/lib/opal/project.rb', line 141 def parse_opalfile opalfile_path = "#{@root_dir}/Opalfile" if File.exist?(opalfile_path) opalfile = File.read(opalfile_path) Opalfile.new(self) do |dsl| dsl.instance_eval(opalfile, opalfile_path, 1) end @has_opalfile = true end end |