module DataAccessible::DataLoader

Public Instance Methods

load_from_file(file) click to toggle source
# File lib/data_accessible/data_loader.rb, line 16
def load_from_file(file)
  contents = File.read(file)
  evaluated_contents = process_erb(contents)
  YAML.load(evaluated_contents) || {}
end
load_source(data_source) click to toggle source
# File lib/data_accessible/data_loader.rb, line 22
def load_source(data_source)
  case data_source
    when Hash
      data_source
    when String
      load_from_file(data_source)
    when Symbol
      load_from_file("#{DataAccessible.data_path}/#{data_source}.yml")
    else
      raise("Invalid data source provided: #{data_source}")
  end
end
process_erb(text) click to toggle source
# File lib/data_accessible/data_loader.rb, line 12
def process_erb(text)
  ERB.new(text).result
end