Class: Portable::Data::Provider

Inherits:
Object
  • Object
show all
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

Methods included from Util::Uniqueness

#assert_no_duplicate_names

Methods included from Util::Pivotable

#pivot_by_name

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