Class: SpecForge::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/loader.rb,
lib/spec_forge/loader/filter.rb,
lib/spec_forge/loader/step_processor.rb

Overview

Loads and processes blueprint YAML files into executable Blueprint objects

The Loader handles the load-time phase of SpecForge, reading YAML files, parsing steps with line numbers, expanding includes, flattening hierarchies, and applying filters.

Defined Under Namespace

Classes: Filter, StepProcessor

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path: nil, paths: [], filter: {}) ⇒ Loader

Creates a new Loader with the specified base path and filter options

Parameters:

  • base_path (Pathname, String, nil) (defaults to: nil)

    Base directory for glob loading (defaults to blueprints/)

  • paths (Array<Pathname, String>) (defaults to: [])

    Specific file paths to load (no globbing)

  • filter (Hash) (defaults to: {})

    Filter options for tags and skip_tags



35
36
37
38
39
# File 'lib/spec_forge/loader.rb', line 35

def initialize(base_path: nil, paths: [], filter: {})
  @base_path = base_path.present? ? Pathname.new(base_path) : SpecForge.forge_path.join("blueprints")
  @paths = Array.wrap(paths).map { |p| Pathname.new(p) }
  @filter = filter
end

Class Method Details

.load_blueprints(base_path: nil, paths: [], tags: [], skip_tags: []) ⇒ Array<Blueprint>, Hash

Loads blueprints from disk with optional filtering

Parameters:

  • base_path (Pathname, String, nil) (defaults to: nil)

    Base directory for glob loading (defaults to blueprints/)

  • paths (Array<Pathname, String>) (defaults to: [])

    Specific file paths to load (no globbing)

  • tags (Array<String>) (defaults to: [])

    Tags to include

  • skip_tags (Array<String>) (defaults to: [])

    Tags to exclude

Returns:

  • (Array<Blueprint>, Hash)

    Loaded blueprint objects and any forge hooks



22
23
24
# File 'lib/spec_forge/loader.rb', line 22

def self.load_blueprints(base_path: nil, paths: [], tags: [], skip_tags: [])
  new(base_path:, paths:, filter: {tags:, skip_tags:}).load
end

Instance Method Details

#loadArray<Blueprint>, Hash

Loads and processes all blueprints, extracting any hook data at the same time

Returns:

  • (Array<Blueprint>, Hash)

    Loaded blueprint objects and any forge hooks



46
47
48
49
50
51
52
53
54
# File 'lib/spec_forge/loader.rb', line 46

def load
  blueprints, forge_hooks = read_blueprints
    .index_by { |b| b[:name] }
    .then { |blueprints| StepProcessor.new(blueprints).run }

  blueprints = Filter.new(blueprints).run(**@filter).map { |b| Blueprint.new(**b) }

  [blueprints, forge_hooks]
end