Class: Portable::Data::Provider
- Inherits:
-
Object
- Object
- Portable::Data::Provider
- Includes:
- Util::Pivotable, Util::Uniqueness
- Defined in:
- lib/portable/data/provider.rb
Overview
Container of data sources that is inputted into a writer alongside a document. It contains all the data sources the writer will use to render a document.
Instance Method Summary collapse
-
#data_source(name) ⇒ Object
Fail hard if we cannot identify which data source to use.
-
#initialize(data_sources: []) ⇒ Provider
constructor
A new instance of Provider.
Methods included from Util::Uniqueness
Methods included from Util::Pivotable
Constructor Details
#initialize(data_sources: []) ⇒ Provider
Returns a new instance of Provider.
21 22 23 24 25 26 27 28 |
# File 'lib/portable/data/provider.rb', line 21 def initialize(data_sources: []) sources = Source.array(data_sources) @data_sources_by_name = pivot_by_name(sources) assert_no_duplicate_names(sources) freeze end |
Instance Method Details
#data_source(name) ⇒ Object
Fail hard if we cannot identify which data source to use. This should help prevent possible configuration issues (i.e. typos.)
32 33 34 35 |
# File 'lib/portable/data/provider.rb', line 32 def data_source(name) data_sources_by_name[name.to_s] || raise(ArgumentError, "data source: '#{name}' cannot be found.") end |