Class: Nocode::Util::ClassLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/nocode/util/class_loader.rb

Overview

Loads a directory full of Ruby classes and returns their relative paths.

Constant Summary collapse

EXTENSION =
'.rb'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ ClassLoader

Returns a new instance of ClassLoader.



11
12
13
14
15
# File 'lib/nocode/util/class_loader.rb', line 11

def initialize(dir)
  @dir = dir

  freeze
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



9
10
11
# File 'lib/nocode/util/class_loader.rb', line 9

def dir
  @dir
end

Instance Method Details

#load!Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/nocode/util/class_loader.rb', line 17

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