Sha256: 9539613939744e9024cfadb9a5b494fca77ec4db167218273a8231a80ab3cc66

Contents?: true

Size: 671 Bytes

Versions: 1

Compression:

Stored size: 671 Bytes

Contents

require "erb"
require "yaml"

module DataAccessible
  module DataLoader
    module_function

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

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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_accessible-1.0.1 lib/data_accessible/data_loader.rb