Class: Rambling::Trie::Configuration::ProviderCollection
- Inherits:
-
Object
- Object
- Rambling::Trie::Configuration::ProviderCollection
- Defined in:
- lib/rambling/trie/configuration/provider_collection.rb
Overview
Collection of configurable providers.
Instance Attribute Summary collapse
-
#default ⇒ TProvider?
The default provider to use when a provider cannot be resolved in #resolve.
-
#name ⇒ Symbol
readonly
The name of this provider collection.
Instance Method Summary collapse
-
#[](format) ⇒ TProvider
Get provider corresponding to a given format.
-
#add(extension, provider) ⇒ TProvider
Adds a new provider to the provider collection.
-
#formats ⇒ Array<Symbol>
Get provider corresponding to a given format.
-
#initialize(name, providers = {}, default = nil) ⇒ ProviderCollection
constructor
Creates a new provider collection.
-
#providers ⇒ Hash<Symbol, TProvider>
List of configured providers.
-
#reset ⇒ void
Resets the provider collection to the initial values.
-
#resolve(filepath) ⇒ TProvider?
Resolves the provider from a filepath based on the file extension.
Constructor Details
#initialize(name, providers = {}, default = nil) ⇒ ProviderCollection
Creates a new provider collection.
29 30 31 32 33 34 35 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 29 def initialize name, providers = {}, default = nil @name = name @configured_providers = providers @configured_default = default || providers.values.first reset end |
Instance Attribute Details
#default ⇒ TProvider? #default=(provider) ⇒ TProvider?
Returns the default provider to use when a provider cannot be resolved in #resolve.
23 24 25 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 23 def default @default end |
#name ⇒ Symbol (readonly)
The name of this provider collection.
10 11 12 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 10 def name @name end |
Instance Method Details
#[](format) ⇒ TProvider
Get provider corresponding to a given format.
84 85 86 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 84 def [] format providers[format] end |
#add(extension, provider) ⇒ TProvider
Adds a new provider to the provider collection.
41 42 43 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 41 def add extension, provider providers[extension] = provider end |
#formats ⇒ Array<Symbol>
Get provider corresponding to a given format.
76 77 78 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 76 def formats providers.keys end |
#providers ⇒ Hash<Symbol, TProvider>
List of configured providers.
53 54 55 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 53 def providers @providers ||= {} end |
#reset ⇒ void
This method returns an undefined value.
Resets the provider collection to the initial values.
66 67 68 69 70 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 66 def reset providers.clear configured_providers.each { |k, v| self[k] = v } self.default = configured_default end |
#resolve(filepath) ⇒ TProvider?
Resolves the provider from a filepath based on the file extension.
60 61 62 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 60 def resolve filepath providers[file_format filepath] || default end |