Module: AccessibleData::DataLoader

Defined in:
lib/accessible_data/data_loader.rb

Class Method Summary collapse

Class Method Details

.load_from_file(file) ⇒ Object



12
13
14
15
16
# File 'lib/accessible_data/data_loader.rb', line 12

def load_from_file(file)
  contents = File.read(file)
  evaluated_contents = process_erb(contents)
  YAML.load(evaluated_contents) || {}
end

.load_source(data_source) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/accessible_data/data_loader.rb', line 18

def load_source(data_source)
  case data_source
    when Hash
      data_source
    when String
      load_from_file(data_source)
    when Symbol
      load_from_file("data/#{data_source}.yml")
    else
      raise("Invalid data source provided: #{data_source}")
  end
end

.process_erb(text) ⇒ Object



8
9
10
# File 'lib/accessible_data/data_loader.rb', line 8

def process_erb(text)
  ERB.new(text).result
end