Class: Wheneverd::Systemd::UnitWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/wheneverd/systemd/unit_writer.rb

Overview

Writes rendered systemd units to a target directory (defaulting to the user unit dir).

Constant Summary collapse

DEFAULT_UNIT_DIR =
File.join(Dir.home, ".config", "systemd", "user").freeze

Class Method Summary collapse

Class Method Details

.write(units, unit_dir: DEFAULT_UNIT_DIR, dry_run: false, prune: false, identifier: nil) ⇒ Array<String>

Returns destination paths.

Parameters:

  • units (Array<Wheneverd::Systemd::Unit>)
  • identifier (String, nil) (defaults to: nil)

    required when pruning

  • unit_dir (String) (defaults to: DEFAULT_UNIT_DIR)
  • dry_run (Boolean) (defaults to: false)

    return paths without writing

  • prune (Boolean) (defaults to: false)

    delete previously generated units for identifier not in units

Returns:

  • (Array<String>)

    destination paths



18
19
20
21
22
23
24
25
26
27
# File 'lib/wheneverd/systemd/unit_writer.rb', line 18

def self.write(units, unit_dir: DEFAULT_UNIT_DIR, dry_run: false, prune: false,
               identifier: nil)
  validate_units!(units)
  dest_dir = File.expand_path(unit_dir.to_s)
  paths = destination_paths(units, dest_dir)
  return paths if dry_run

  write_units(units, paths, dest_dir, prune: prune, identifier: identifier)
  paths
end