Class: HeyYou::Config::DataSource
- Inherits:
-
Object
- Object
- HeyYou::Config::DataSource
- Extended by:
- Configurable
- Defined in:
- lib/hey_you/config/data_source.rb
Defined Under Namespace
Classes: InvalidOptionsError
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#source_class ⇒ Object
Returns the value of attribute source_class.
-
#source_instance ⇒ Object
Returns the value of attribute source_instance.
Instance Method Summary collapse
-
#initialize ⇒ DataSource
constructor
A new instance of DataSource.
- #load_data ⇒ Object
Methods included from Configurable
Constructor Details
#initialize ⇒ DataSource
Returns a new instance of DataSource.
12 13 14 15 16 |
# File 'lib/hey_you/config/data_source.rb', line 12 def initialize @type = DEFAULTS[:type] = DEFAULTS[:options] @source_class = HeyYou::DataSource::Yaml end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/hey_you/config/data_source.rb', line 10 def end |
#source_class ⇒ Object
Returns the value of attribute source_class.
10 11 12 |
# File 'lib/hey_you/config/data_source.rb', line 10 def source_class @source_class end |
#source_instance ⇒ Object
Returns the value of attribute source_instance.
10 11 12 |
# File 'lib/hey_you/config/data_source.rb', line 10 def source_instance @source_instance end |
Instance Method Details
#load_data ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hey_you/config/data_source.rb', line 18 def load_data return source_instance.load_collections if source_instance if source_class.nil? raise InvalidDataSourceError, 'You must pass `config.data_source.source_class` in configuration.' end source_class.new(**).load_collections rescue ArgumentError => err problem_fields = err..gsub(/missing keyword(.?):\s/, '').split(', ').map { |f| "`#{f}`" }.join(', ') field_word = problem_fields.split(', ').size > 1 ? 'fields' : 'field' msg = "You must pass #{field_word} #{problem_fields} for `config.data_source.options` in configuration" raise InvalidOptionsError, msg end |