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 ⇒ Object?
The default provider to use when a provider cannot be resolved in #resolve.
-
#name ⇒ String
readonly
The name of this provider collection.
Instance Method Summary collapse
-
#[](format) ⇒ Object
Get provider corresponding to a given format.
-
#add(extension, provider) ⇒ Object
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
List of configured providers.
-
#reset ⇒ Object
Resets the provider collection to the initial values.
-
#resolve(filepath) ⇒ Object
Resolves the provider from a filepath based on the file extension.
Constructor Details
#initialize(name, providers = {}, default = nil) ⇒ ProviderCollection
Creates a new provider collection.
30 31 32 33 34 35 36 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 30 def initialize name, providers = {}, default = nil @name = name @configured_providers = providers @configured_default = default || providers.values.first reset end |
Instance Attribute Details
#default ⇒ Object? #default=(provider) ⇒ Object?
Returns the default provider to use when a provider cannot be resolved in #resolve.
24 25 26 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 24 def default @default end |
#name ⇒ String (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) ⇒ Object
Get provider corresponding to a given format.
91 92 93 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 91 def [] format providers[format] end |
#add(extension, provider) ⇒ Object
Adds a new provider to the provider collection.
43 44 45 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 43 def add extension, provider providers[extension] = provider end |
#formats ⇒ Array<Symbol>
Get provider corresponding to a given format.
82 83 84 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 82 def formats providers.keys end |
#providers ⇒ Hash
List of configured providers.
59 60 61 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 59 def providers @providers ||= {} end |
#reset ⇒ Object
Resets the provider collection to the initial values.
72 73 74 75 76 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 72 def reset providers.clear configured_providers.each { |k, v| self[k] = v } self.default = configured_default end |
#resolve(filepath) ⇒ Object
Resolves the provider from a filepath based on the file extension.
67 68 69 |
# File 'lib/rambling/trie/configuration/provider_collection.rb', line 67 def resolve filepath providers[file_format filepath] || default end |