Class: Kozeki::LoaderChain

Inherits:
Object
  • Object
show all
Defined in:
lib/kozeki/loader_chain.rb

Instance Method Summary collapse

Constructor Details

#initialize(loaders:, decorators:) ⇒ LoaderChain

Returns a new instance of LoaderChain.



3
4
5
6
# File 'lib/kozeki/loader_chain.rb', line 3

def initialize(loaders:, decorators:)
  @loaders = loaders
  @decorators = decorators
end

Instance Method Details

#try_readObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kozeki/loader_chain.rb', line 8

def try_read(...)
  @loaders.each do |loader|
    source = loader.try_read(...)
    next unless source
    @decorators.each do |decorator|
      decorator.call(source.meta, source)
    end
    return source
  end
  nil
end