Class: Workflows::Registry
- Inherits:
-
Object
- Object
- Workflows::Registry
- Defined in:
- lib/workflows/registry.rb
Overview
Loads workflow definitions from Markdown files and provides lookup. Scans two directories:
1. Built-in workflows shipped with Anima (workflows/ in the gem root)
2. User-defined workflows (~/.anima/workflows/)
User workflows override built-in ones when names collide.
Constant Summary collapse
- BUILTIN_DIR =
File.("../../workflows", __dir__).freeze
- USER_DIR =
File.("~/.anima/workflows").freeze
Instance Attribute Summary collapse
-
#workflows ⇒ Hash{String => Definition}
readonly
Loaded definitions keyed by name.
Class Method Summary collapse
-
.instance ⇒ Registry
Returns the global registry, lazily loaded on first access.
-
.reload! ⇒ Registry
Reloads the global registry from disk.
Instance Method Summary collapse
- #any? ⇒ Boolean
-
#available_names ⇒ Array<String>
Registered workflow names.
-
#catalog ⇒ Hash{String => String}
Workflow names and descriptions for inclusion in the analytical brain’s context.
-
#find(name) ⇒ Definition?
Looks up a named workflow definition.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#load_all ⇒ self
Loads definitions from both built-in and user directories.
-
#load_directory(dir) ⇒ void
Loads workflow definitions from a single directory (flat .md files only).
- #size ⇒ Integer
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
16 17 18 |
# File 'lib/workflows/registry.rb', line 16 def initialize @workflows = {} end |
Instance Attribute Details
#workflows ⇒ Hash{String => Definition} (readonly)
Returns loaded definitions keyed by name.
11 12 13 |
# File 'lib/workflows/registry.rb', line 11 def workflows @workflows end |
Class Method Details
.instance ⇒ Registry
Returns the global registry, lazily loaded on first access.
23 24 25 |
# File 'lib/workflows/registry.rb', line 23 def self.instance @instance ||= new.load_all end |
.reload! ⇒ Registry
Reloads the global registry from disk.
30 31 32 |
# File 'lib/workflows/registry.rb', line 30 def self.reload! @instance = new.load_all end |
Instance Method Details
#any? ⇒ Boolean
80 81 82 |
# File 'lib/workflows/registry.rb', line 80 def any? @workflows.any? end |
#available_names ⇒ Array<String>
Returns registered workflow names.
75 76 77 |
# File 'lib/workflows/registry.rb', line 75 def available_names @workflows.keys end |
#catalog ⇒ Hash{String => String}
Workflow names and descriptions for inclusion in the analytical brain’s context.
70 71 72 |
# File 'lib/workflows/registry.rb', line 70 def catalog @workflows.transform_values(&:description) end |
#find(name) ⇒ Definition?
Looks up a named workflow definition.
63 64 65 |
# File 'lib/workflows/registry.rb', line 63 def find(name) @workflows[name] end |
#load_all ⇒ self
Loads definitions from both built-in and user directories. User definitions override built-in ones with the same name.
38 39 40 41 42 |
# File 'lib/workflows/registry.rb', line 38 def load_all load_directory(BUILTIN_DIR) load_directory(USER_DIR) self end |
#load_directory(dir) ⇒ void
This method returns an undefined value.
Loads workflow definitions from a single directory (flat .md files only).
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/workflows/registry.rb', line 48 def load_directory(dir) return unless Dir.exist?(dir) Dir.glob(File.join(dir, "*.md")).sort.each do |path| definition = Definition.from_file(path) @workflows[definition.name] = definition rescue InvalidDefinitionError => error Rails.logger.warn("Skipping invalid workflow definition #{path}: #{error.}") end end |
#size ⇒ Integer
85 86 87 |
# File 'lib/workflows/registry.rb', line 85 def size @workflows.size end |