Class: RubySkills::Manifest

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

Overview

Loads and evaluates a project Skillfile.

The Skillfile is Ruby DSL. Each skill declaration becomes a Skill stored in #skills.

Examples:

Load the Skillfile from the current project

manifest = RubySkills::Manifest.new.load!
manifest.skills

Since:

  • 0.1.0

Defined Under Namespace

Classes: Skill

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: default_skill_path) ⇒ Manifest

Returns a new instance of Manifest.

Parameters:

  • path (Pathname, String) (defaults to: default_skill_path)

    path to the Skillfile

Since:

  • 0.1.0



37
38
39
40
# File 'lib/ruby_skills/manifest.rb', line 37

def initialize(path: default_skill_path)
  @path = path
  @skills = []
end

Instance Attribute Details

#skillsArray<Skill> (readonly)

Returns skills declared in the Skillfile.

Returns:

  • (Array<Skill>)

    skills declared in the Skillfile

Since:

  • 0.1.0



34
35
36
# File 'lib/ruby_skills/manifest.rb', line 34

def skills
  @skills
end

Instance Method Details

#load!Manifest

Read and evaluate the Skillfile, populating #skills.

Returns:

Raises:

Since:

  • 0.1.0



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby_skills/manifest.rb', line 46

def load!
  unless @path.exist?
    raise RubySkills::Error,
          "Skillfile not found. Run `ruby-skills init` first."
  end

  instance_eval(@path.read, @path.to_s, 1)

  self
rescue SyntaxError => e
  raise RubySkills::Error, "Invalid Skillfile: #{e.message}"
end

#skill(name, github: nil, path: nil, version: nil) ⇒ void

This method returns an undefined value.

Declare a skill in the Skillfile DSL.

Exactly one source must be provided: github or path.

Parameters:

  • name (String)

    skill identifier

  • github (String, nil) (defaults to: nil)

    GitHub repository in owner/name form

  • path (String, nil) (defaults to: nil)

    local filesystem path to the skill

  • version (String, nil) (defaults to: nil)

    optional pinned version

Raises:

Since:

  • 0.1.0



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ruby_skills/manifest.rb', line 69

def skill(name, github: nil, path: nil, version: nil)
  unless github || path
    raise RubySkills::Error,
          "#{name}: either github or path: must be provided"
  end

  @skills << Skill.new(
    name: name,
    github: github,
    path: path,
    version: version
  )
end