Class: Textus::Step::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/step/loader.rb

Overview

Convention discovery: glob .textus/steps/<kind>/<name>.rb, load each file, validate the class it defines against the discovered kind, assign the discovered name, and register it. No global queue, no Textus.hook.

Constant Summary collapse

BASE_FOR =
{
  fetch: Step::Fetch, transform: Step::Transform,
  validate: Step::Validate, observe: Step::Observe
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(registry:) ⇒ Loader

Returns a new instance of Loader.



14
15
16
# File 'lib/textus/step/loader.rb', line 14

def initialize(registry:)
  @registry = registry
end

Instance Method Details

#load_dir(dir) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/textus/step/loader.rb', line 18

def load_dir(dir)
  return unless File.directory?(dir)

  loaded_paths = Set.new
  Dir.glob(File.join(dir, "**/*.rb")).sort.each do |path| # rubocop:disable Lint/RedundantDirGlobSort
    real_path = File.realpath(path)
    next if loaded_paths.include?(real_path)

    loaded_paths << real_path
    load_one(dir, path)
  end
end