Class: Roadie::ProviderList
- Inherits:
-
Object
- Object
- Roadie::ProviderList
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/roadie/provider_list.rb
Overview
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.
Class Method Summary collapse
-
.empty ⇒ Object
Returns a new empty list.
-
.wrap(*providers) ⇒ Object
Wrap a single provider, or a list of providers into a ProviderList.
Instance Method Summary collapse
- #<< ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Object
- #find_stylesheet(name) ⇒ Stylesheet?
-
#find_stylesheet!(name) ⇒ Stylesheet
Tries to find the given stylesheet and raises an ProvidersFailed error if no provider could find the asset.
-
#initialize(providers) ⇒ ProviderList
constructor
A new instance of ProviderList.
- #last ⇒ Object
- #pop ⇒ Object
- #push ⇒ Object
- #shift ⇒ Object
- #size ⇒ Object
-
#to_ary ⇒ Object
ProviderList can be coerced to an array.
- #to_s ⇒ Object
- #unshift ⇒ Object
Constructor Details
#initialize(providers) ⇒ ProviderList
Returns a new instance of ProviderList.
40 41 42 |
# File 'lib/roadie/provider_list.rb', line 40 def initialize(providers) @providers = providers end |
Class Method Details
.empty ⇒ Object
Returns a new empty list.
36 37 38 |
# File 'lib/roadie/provider_list.rb', line 36 def self.empty new([]) end |
.wrap(provider_list) ⇒ Object .wrap(provider) ⇒ Object .wrap(provider1, provider2, ...) ⇒ Object
Wrap a single provider, or a list of providers into a Roadie::ProviderList.
27 28 29 30 31 32 33 |
# File 'lib/roadie/provider_list.rb', line 27 def self.wrap(*providers) if providers.size == 1 && providers.first.instance_of?(self) providers.first else new(providers.flatten) end end |
Instance Method Details
#<< ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#each ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#empty? ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#find_stylesheet(name) ⇒ Stylesheet?
45 46 47 48 49 50 51 |
# File 'lib/roadie/provider_list.rb', line 45 def find_stylesheet(name) @providers.each do |provider| css = provider.find_stylesheet(name) return css if css end nil end |
#find_stylesheet!(name) ⇒ Stylesheet
Tries to find the given stylesheet and raises an Roadie::ProvidersFailed error if no provider could find the asset.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/roadie/provider_list.rb', line 57 def find_stylesheet!(name) errors = [] @providers.each do |provider| return provider.find_stylesheet!(name) rescue CssNotFound => error errors << error end raise ProvidersFailed.new( css_name: name, providers: self, errors: errors ) end |
#last ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#pop ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#push ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#shift ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#size ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |
#to_ary ⇒ Object
ProviderList can be coerced to an array. This makes Array#flatten work with it, among other things.
79 80 81 |
# File 'lib/roadie/provider_list.rb', line 79 def to_ary to_a end |
#to_s ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/roadie/provider_list.rb', line 69 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]\n" end |
#unshift ⇒ Object
101 |
# File 'lib/roadie/provider_list.rb', line 101 def_delegators :@providers, :each, :size, :empty?, :push, :<<, :pop, :unshift, :shift, :last |