Class: Himari::ProviderChain

Inherits:
Object
  • Object
show all
Defined in:
lib/himari/provider_chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(providers) ⇒ ProviderChain

Returns a new instance of ProviderChain.

Parameters:



6
7
8
# File 'lib/himari/provider_chain.rb', line 6

def initialize(providers)
  @providers = providers
end

Instance Attribute Details

#providersObject (readonly)

Returns the value of attribute providers.



10
11
12
# File 'lib/himari/provider_chain.rb', line 10

def providers
  @providers
end

Instance Method Details

#collect(**hint) ⇒ Object



22
23
24
25
26
# File 'lib/himari/provider_chain.rb', line 22

def collect(**hint)
  @providers.flat_map do |provider|
    provider.collect(**hint)
  end
end

#find(**hint, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/himari/provider_chain.rb', line 12

def find(**hint, &block)
  block ||= proc { |i, h| i.match_hint?(**h) } # ItemProvider#collect doesn't guarantee exact matches, so do exact match by match_hint?
  @providers.each do |provider|
    provider.collect(**hint).each do |item|
      return item if block.call(item, hint)
    end
  end
  nil
end