Module: Trane::ContractLoader

Defined in:
lib/trane/contract_loader.rb

Overview

Single source of truth for the contract-file load order, used by both the Engine's to_prepare block and any test harness that replays the boot-time load (spec/integration/integration_helper.rb) — keeping the two from silently diverging.

Order:

Phase 1 — every errors.rb from every base path (in declaration order).
Phase 2 — all other .rb files from every base path (sorted within each).

Class Method Summary collapse

Class Method Details

.each_file(root, contracts_paths) ⇒ Object

Yields the absolute path (String) of each contract file in load order.

Parameters:

  • root (Pathname)

    the application root (e.g. Rails.root)

  • contracts_paths (Array<String>)

    base paths relative to root



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trane/contract_loader.rb', line 17

def self.each_file(root, contracts_paths)
  errors_files = contracts_paths.map { |path| root.join(path, "errors.rb") }
  errors_files.each { |file| yield file.to_s if file.exist? }

  contracts_paths.each_with_index do |path, i|
    errors_file = errors_files[i].to_s
    Dir[root.join(path, "**/*.rb")].sort.each do |file|
      yield file unless file == errors_file
    end
  end
end