Module: StockCruncher::Config
- Defined in:
- lib/stockcruncher/config.rb
Overview
this is a module to load configuration file and environment variable
Class Method Summary collapse
-
.load(file) ⇒ Object
Load config file and override with env variables.
- .overload(config, prefix, component, items) ⇒ Object
- .overload_alphavantage(config) ⇒ Object
- .overload_influxdb(config) ⇒ Object
Class Method Details
.load(file) ⇒ Object
Load config file and override with env variables
12 13 14 15 16 |
# File 'lib/stockcruncher/config.rb', line 12 def load(file) config = YAML.load_file(file) overload_alphavantage(config) overload_influxdb(config) end |
.overload(config, prefix, component, items) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/stockcruncher/config.rb', line 18 def overload(config, prefix, component, items) items.each do |key| var = "#{prefix}#{key.upcase}" config[component][key] = ENV[var] unless ENV[var].nil? end config end |
.overload_alphavantage(config) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/stockcruncher/config.rb', line 26 def overload_alphavantage(config) prefix = 'SCR_AV_' component = 'AlphaVantage' items = %w[apikey] overload(config, prefix, component, items) end |
.overload_influxdb(config) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/stockcruncher/config.rb', line 33 def overload_influxdb(config) prefix = 'SCR_IDB_' component = 'InfluxDB' items = %w[scheme host port user password dbname] overload(config, prefix, component, items) end |