Module: Belajar::Loadable

Included in:
Belajar::Loading::Chapters, Belajar::Loading::Courses, Belajar::Loading::Units
Defined in:
lib/belajar/loadable.rb

Instance Method Summary collapse

Instance Method Details

#load(path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/belajar/loadable.rb', line 3

def load(path)
  return [] unless Dir.exist?(path)

  dirs = Dir.entries(path).select do |entry|
    !entry.match(/\./)
  end

  dirs.sort.map do |dir|
    dir_path   = File.join(path, dir)
    module_name = demodulize(to_s)
    class_name = singularize(module_name)
    belajar_class(class_name).new(dir_path)
  end
end