Module: Lyman::CLI::Planter
- Defined in:
- lib/lyman/cli/planter.rb
Overview
Turns a registry entry into planted bytes and writes them. Rendering
and hashing are kept together deliberately: the hash must always be a
hash of what actually landed on disk (banner included), never of the
bare source file, or update would flag every managed artifact as
locally modified on first run.
Constant Summary collapse
- BANNER =
<<~RUBY # Managed by lyman — extend, don't modify. `lyman eject %<name>s` takes # ownership; see .lyman/manifest.yml. RUBY
Class Method Summary collapse
- .hash(bytes) ⇒ Object
- .plant(name, spec, project_root:, source_root: Registry::GEM_ROOT) ⇒ Object
- .render(name, spec, source_root: Registry::GEM_ROOT) ⇒ Object
Class Method Details
.hash(bytes) ⇒ Object
35 36 37 |
# File 'lib/lyman/cli/planter.rb', line 35 def self.hash(bytes) Digest::SHA256.hexdigest(bytes) end |
.plant(name, spec, project_root:, source_root: Registry::GEM_ROOT) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/lyman/cli/planter.rb', line 27 def self.plant(name, spec, project_root:, source_root: Registry::GEM_ROOT) bytes = render(name, spec, source_root: source_root) dest = File.join(project_root, spec[:dest]) FileUtils.mkdir_p(File.dirname(dest)) File.write(dest, bytes) bytes end |
.render(name, spec, source_root: Registry::GEM_ROOT) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/lyman/cli/planter.rb', line 18 def self.render(name, spec, source_root: Registry::GEM_ROOT) source = File.read(Registry.source_path(spec, source_root: source_root)) if spec[:role] == :managed && spec[:dest].end_with?(".rb") format(BANNER, name: name) + source else source end end |