class Dotenvious::Loaders::YamlFile

Attributes

filename[R]

Public Class Methods

load_from(filename) click to toggle source
# File lib/dotenvious/loaders/yaml_file.rb, line 6
def self.load_from(filename)
  new(filename).load
end
new(filename) click to toggle source
# File lib/dotenvious/loaders/yaml_file.rb, line 10
def initialize(filename)
  @filename = filename
end

Public Instance Methods

load() click to toggle source
# File lib/dotenvious/loaders/yaml_file.rb, line 14
def load
  if file_missing?
    puts "This repo does not have an #{filename} file"
    return {}
  end
  Hash.new.tap do |environment|
    environment_variables.each do |(k, v)|
      environment[k] = v.to_s
    end
  end
end

Private Instance Methods

environment_variables() click to toggle source
# File lib/dotenvious/loaders/yaml_file.rb, line 38
def environment_variables
  begin
    file['machine']['environment']
  rescue NoMethodError => e
    puts "Error: #{filename} does not have a proper machine environment setup."
    puts "The program will now exit."
    exit
  end
end
file() click to toggle source
# File lib/dotenvious/loaders/yaml_file.rb, line 34
def file
  YAML.load_file(filename)
end
file_missing?() click to toggle source
# File lib/dotenvious/loaders/yaml_file.rb, line 30
def file_missing?
  !File.exists?(filename)
end