Sha256: 1767fb01bc4eefbd695d5cd5c05589bf22850206146602f538d00f52fd689e03

Contents?: true

Size: 983 Bytes

Versions: 2

Compression:

Stored size: 983 Bytes

Contents

require 'yaml'

module Dotenvious
  module Loaders
    class YamlFile
      def self.load_from(filename)
        new(filename).load
      end

      def initialize(filename)
        @filename = filename
      end

      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

      attr_reader :filename

      def file_missing?
        !File.exists?(filename)
      end

      def file
        YAML.load_file(filename)
      end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dotenvious-0.0.7 lib/dotenvious/loaders/yaml_file.rb
dotenvious-0.0.6 lib/dotenvious/loaders/yaml_file.rb