Sha256: 535db7c7c42766a434d675a3ddd5780dd16adb609973b72916205d45db4417ad

Contents?: true

Size: 741 Bytes

Versions: 3

Compression:

Stored size: 741 Bytes

Contents

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

      def initialize(filename)
        @filename = filename
      end

      def load
        #took from Dotenv source code whoops
        if file_missing?
          puts "This repo does not have an #{filename} file"
          return {}
        end
        Hash.new.tap do |environment|
          file.each do |line|
            environment[$1] = $2 if line =~ /\A([\w_]+)=(.*)\z/
          end
        end
      end

      private

      attr_reader :filename

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

      def file
        File.read(filename).split("\n")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dotenvious-0.0.7 lib/dotenvious/loaders/dotenv_file.rb
dotenvious-0.0.6 lib/dotenvious/loaders/dotenv_file.rb
dotenvious-0.0.5 lib/dotenvious/loaders/dotenv_file.rb