Refactor CodeOcean::Config class
The new architecture memorizes settings (which we mostly did after reading the config so far) and also exposes the resulting file path as well as further settings. This change is a prerequisite to define a dependency with Sprockets.
This commit is contained in:

committed by
Sebastian Serth

parent
dcaedfa9fe
commit
336519b21d
@ -2,12 +2,16 @@
|
||||
|
||||
module CodeOcean
|
||||
class Config
|
||||
def initialize(filename)
|
||||
@filename = filename
|
||||
attr_reader :path, :read
|
||||
|
||||
def initialize(filename, options = {})
|
||||
@path = Rails.root.join('config', "#{filename}.yml#{options[:erb] ? '.erb' : ''}")
|
||||
@read = parse(options)
|
||||
end
|
||||
|
||||
def read(options = {})
|
||||
path = Rails.root.join('config', "#{@filename}.yml#{options[:erb] ? '.erb' : ''}")
|
||||
private
|
||||
|
||||
def parse(options)
|
||||
if ::File.exist?(path)
|
||||
yaml_content = ::File.new(path, 'r').read || ''
|
||||
yaml_content = ERB.new(yaml_content).result if options[:erb]
|
||||
|
Reference in New Issue
Block a user