Module: Cyborg::ConfigData
Instance Method Summary collapse
Instance Method Details
#data_files(*roots) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cyborg/config_data.rb', line 20 def data_files(*roots) files = [] [roots].flatten.each do |root| files.concat Dir[File.join(root, 'config/data/**/*.json')] files.concat Dir[File.join(root, 'config/data/**/*.yml')] end files.flatten.compact.uniq end |
#read(*roots) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cyborg/config_data.rb', line 4 def read(*roots) @data ||= {} data_files(*roots).each do |path| name = File.basename(path, '.*') case File.extname(path) when '.json' @data[name] = JSON.parse(File.read(path)) when '.yml' @data[name] = YAML.load_file(path) end end @data end |