class Roadie::ProviderList
An asset provider that just composes a list of other asset providers.
Give it a list of providers and they will all be tried in order.
{ProviderList} behaves like an Array, and an asset provider, and can be coerced into an array.
Public Class Methods
empty()
click to toggle source
Returns a new empty list.
# File lib/roadie/provider_list.rb, line 34 def self.empty() new([]) end
new(providers)
click to toggle source
# File lib/roadie/provider_list.rb, line 36 def initialize(providers) @providers = providers end
wrap(*providers)
click to toggle source
Wrap a single provider, or a list of providers into a {ProviderList}.
@overload wrap(provider_list)
@param [ProviderList] provider_list An actual instance of {ProviderList}. @return The passed in provider_list
@overload wrap(provider)
@param [asset provider] provider @return a new {ProviderList} with just the passed provider in it
@overload wrap(provider1, provider2, …)
@return a new {ProviderList} with all the passed providers in it.
# File lib/roadie/provider_list.rb, line 25 def self.wrap(*providers) if providers.size == 1 && providers.first.class == self providers.first else new(providers.flatten) end end
Public Instance Methods
find_stylesheet(name)
click to toggle source
@return [Stylesheet, nil]
# File lib/roadie/provider_list.rb, line 41 def find_stylesheet(name) @providers.each do |provider| css = provider.find_stylesheet(name) return css if css end nil end
find_stylesheet!(name)
click to toggle source
Tries to find the given stylesheet and raises an {ProvidersFailed} error if no provider could find the asset.
@return [Stylesheet]
# File lib/roadie/provider_list.rb, line 53 def find_stylesheet!(name) errors = [] @providers.each do |provider| begin return provider.find_stylesheet!(name) rescue CssNotFound => error errors << error end end raise ProvidersFailed.new(name, self, errors) end
to_ary()
click to toggle source
ProviderList can be coerced to an array. This makes Array#flatten work with it, among other things.
# File lib/roadie/provider_list.rb, line 75 def to_ary() to_a end
to_s()
click to toggle source
# File lib/roadie/provider_list.rb, line 65 def to_s list = @providers.map { |provider| # Indent every line one level provider.to_s.split("\n").join("\n\t") } "ProviderList: [\n\t#{list.join(",\n\t")}\n]" end