Sha256: c50d24d0dd5bf68fd6b4ff436a7306ff32be4901c3f1bd5f1afb325a75b4e13e

Contents?: true

Size: 575 Bytes

Versions: 7

Compression:

Stored size: 575 Bytes

Contents

# frozen_string_literal: true

module Nocode
  module Util
    # Loads a directory full of Ruby classes and returns their relative paths.
    class ClassLoader
      EXTENSION = '.rb'

      attr_reader :dir

      def initialize(dir)
        @dir = dir

        freeze
      end

      def load!
        Dir[File.join(dir, '**', "*#{EXTENSION}")].sort.map do |step_path|
          require step_path

          step_path
            .delete_prefix(dir)
            .delete_prefix(File::SEPARATOR)
            .delete_suffix(EXTENSION)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nocode-0.0.10 lib/nocode/util/class_loader.rb
nocode-0.0.9 lib/nocode/util/class_loader.rb
nocode-0.0.8 lib/nocode/util/class_loader.rb
nocode-0.0.7 lib/nocode/util/class_loader.rb
nocode-0.0.6 lib/nocode/util/class_loader.rb
nocode-0.0.5 lib/nocode/util/class_loader.rb
nocode-0.0.4 lib/nocode/util/class_loader.rb