Class: MdRecord::CategorizedLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/md_record/categorized_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(path:, categories:) ⇒ CategorizedLoader

Returns a new instance of CategorizedLoader.



5
6
7
8
# File 'lib/md_record/categorized_loader.rb', line 5

def initialize(path:, categories:)
  @path = Pathname.new(path).expand_path
  @categories = categories
end

Instance Method Details

#loadObject



10
11
12
13
14
15
16
17
18
# File 'lib/md_record/categorized_loader.rb', line 10

def load
  @categories.keys.flat_map do |category|
    if category_path(category).directory?
      category_files(category).map { |file| yield file, category }
    else
      []
    end
  end
end