Class: RubySkills::Lockfile

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_skills/lockfile.rb

Overview

Reads and writes the project Skills.lock file.

The lockfile records installed skill names, versions, and sources so later installs and removals stay consistent.

Examples:

List installed skills

RubySkills::Lockfile.new.skills

See Also:

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(config: Config.new) ⇒ Lockfile

Returns a new instance of Lockfile.

Parameters:

  • config (RubySkills::Config) (defaults to: Config.new)

    project paths used to locate Skills.lock

Since:

  • 0.1.0



16
17
18
# File 'lib/ruby_skills/lockfile.rb', line 16

def initialize(config: Config.new)
  @config = config
end

Instance Method Details

#add(name, version:, source:) ⇒ void

This method returns an undefined value.

Record an installed skill in the lockfile.

Parameters:

  • name (String)

    skill identifier

  • version (String)

    installed skill version

  • source (String)

    origin used to install the skill

Since:

  • 0.1.0



41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby_skills/lockfile.rb', line 41

def add(name, version:, source:)
  data = load_data

  data["skills"][name] = {
    "version" => version,
    "source" => source
  }

  write(data)
end

#remove(name) ⇒ void

This method returns an undefined value.

Drop a skill from the lockfile.

Parameters:

  • name (String)

    skill identifier to remove

Since:

  • 0.1.0



56
57
58
59
60
61
62
# File 'lib/ruby_skills/lockfile.rb', line 56

def remove(name)
  data = load_data

  data["skills"].delete(name)

  write(data)
end

#skillsHash{String => Hash}

Installed skills stored in the lockfile.

Returns:

  • (Hash{String => Hash})

    skill names mapped to version and source

Since:

  • 0.1.0



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_skills/lockfile.rb', line 23

def skills
  return {} unless @config.lockfile_path.exist?

  data = YAML.safe_load_file(
    @config.lockfile_path,
    permitted_classes: [],
    aliases: true
  )

  data.fetch("skills", {})
end