Module: Moon::DataLoader

Defined in:
lib/moon/packages/dataman/data_loader.rb

Overview

DataLoader is a helper module for loading data from the filesystem. DataLoader assumes that all data is serialized as YAML with the file extension .yml.

Class Method Summary collapse

Class Method Details

.file(filename) ⇒ Object

Loads data from a file and loads it using YAML

Parameters:


30
31
32
33
# File 'lib/moon/packages/dataman/data_loader.rb', line 30

def self.file(filename)
  STDERR.puts "[#{self}] .file(#{filename})"
  string raw_file(filename)
end

.raw_file(filename) ⇒ String

Loads data from a file as is.

Parameters:

Returns:


23
24
25
# File 'lib/moon/packages/dataman/data_loader.rb', line 23

def self.raw_file(filename)
  File.read("#{rootpath}/#{filename}.yml")
end

.rootpathString

Rootpath of the data, defauled to “data”

Returns:


8
9
10
# File 'lib/moon/packages/dataman/data_loader.rb', line 8

def self.rootpath
  "data"
end

.string(string) ⇒ String

Loads data from a String

Returns:


15
16
17
# File 'lib/moon/packages/dataman/data_loader.rb', line 15

def self.string(string)
  YAML.load(string)
end