Module: SparkEngine::Data

Extended by:
Data
Included in:
Data
Defined in:
lib/spark_engine/data.rb

Instance Method Summary collapse

Instance Method Details

#data_files(*roots) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/spark_engine/data.rb', line 21

def data_files(*roots)
  files = []
  [roots].flatten.each do |root|
    files.concat Dir[File.join(root, 'config', SparkEngine.plugin.name, '**/*.json')]
    files.concat Dir[File.join(root, 'config', SparkEngine.plugin.name, '**/*.yml')]
  end
  files.flatten.compact.uniq
end

#readObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/spark_engine/data.rb', line 5

def read
  data_files(SparkEngine.plugin.root, Rails.root).each_with_object({}) do |path, data|
    name = File.basename(path, '.*')
    data[name] ||= {}

    case File.extname(path)
    when '.json'
      data[name].merge!(JSON.parse(File.read(path)))
    when '.yml'
      data[name].merge!(YAML.load_file(path))
    end

    data
  end
end