Module: Toys::SourceSpec
- Defined in:
- lib/toys/source_spec.rb
Overview
A source spec is an unresolved description of a source: its kind, and the information needed to locate it.
Source specs cover the sources added to a SourceList, and the
sources declared from within a toys file using the load, load_git, and
load_gem directives. (A source that a Loader finds by walking a
directory has no source spec.)
A source spec says only what to load; it performs no filesystem access, no git fetch, and no gem activation. Those happen later, when a loader resolves the spec into a SourceInfo. A spec does, however, check the types of its arguments when it is created, so a malformed description is reported at that point rather than at resolution time. Create specs using the factory methods SourceSpec.path, SourceSpec.git, SourceSpec.gem, and SourceSpec.block, each of which returns an instance of the corresponding subclass of Base.
Source specs are immutable and compare by value, so two specs describing the same source are equal and hash alike. (A block spec's proc compares by identity.)
Defined Under Namespace
Classes: Base, Block, Gem, Git, Path
Constant Summary collapse
- EMPTY =
An empty SourceSpec. Used as a synthetic root SourceSpec for tools without a true source (such as the default root tool, and synthetic tools used for testing.)
Block.new(proc {}, nil, "(No source)").freeze
Class Method Summary collapse
-
.block(context_directory: nil, source_name: nil, &block) ⇒ Toys::SourceSpec::Block
Create a spec for a block of DSL code.
-
.gem(name, version: nil, path: nil, toys_dir: nil, context_directory: nil, source_name: nil, on_missing: nil, default_confirm: nil) ⇒ Toys::SourceSpec::Gem
Create a spec for a gem.
-
.git(remote, path: nil, commit: nil, update: false, context_directory: nil, source_name: nil) ⇒ Toys::SourceSpec::Git
Create a spec for a git repository.
-
.path(path, relative_paths: nil, context_directory: nil, source_name: nil) ⇒ Toys::SourceSpec::Path
Create a spec for a file system path.
Class Method Details
.block(context_directory: nil, source_name: nil, &block) ⇒ Toys::SourceSpec::Block
Create a spec for a block of DSL code.
145 146 147 |
# File 'lib/toys/source_spec.rb', line 145 def block(context_directory: nil, source_name: nil, &block) Block.new(block, context_directory, source_name) end |
.gem(name, version: nil, path: nil, toys_dir: nil, context_directory: nil, source_name: nil, on_missing: nil, default_confirm: nil) ⇒ Toys::SourceSpec::Gem
Create a spec for a gem.
124 125 126 127 |
# File 'lib/toys/source_spec.rb', line 124 def gem(name, version: nil, path: nil, toys_dir: nil, context_directory: nil, source_name: nil, on_missing: nil, default_confirm: nil) Gem.new(name, version, path, toys_dir, context_directory, source_name, on_missing, default_confirm) end |
.git(remote, path: nil, commit: nil, update: false, context_directory: nil, source_name: nil) ⇒ Toys::SourceSpec::Git
Create a spec for a git repository.
84 85 86 |
# File 'lib/toys/source_spec.rb', line 84 def git(remote, path: nil, commit: nil, update: false, context_directory: nil, source_name: nil) Git.new(remote, path, commit, update, context_directory, source_name) end |
.path(path, relative_paths: nil, context_directory: nil, source_name: nil) ⇒ Toys::SourceSpec::Path
Create a spec for a file system path.
54 55 56 |
# File 'lib/toys/source_spec.rb', line 54 def path(path, relative_paths: nil, context_directory: nil, source_name: nil) Path.new(path, relative_paths, context_directory, source_name) end |