Sha256: 7590e4e60ef8cdd80e3911b9a3538dbccffae2bc514cd182f414e7f9ad22b6b6

Contents?: true

Size: 928 Bytes

Versions: 24

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true
require 'hako/env_provider'

module Hako
  module EnvProviders
    class File < EnvProvider
      def initialize(root_path, options)
        unless options['path']
          validation_error!('path must be set')
        end
        @path = root_path.join(options['path'])
      end

      def ask(variables)
        env = {}
        read_from_file do |key, val|
          if variables.include?(key)
            env[key] = val
          end
        end
        env
      end

      private

      def read_from_file(&block)
        ::File.open(@path) do |f|
          f.each_line do |line|
            line.chomp!
            line.lstrip!
            if line[0] == '#'
              # line comment
              next
            end
            key, val = line.split('=', 2)
            if val
              block.call(key, val)
            end
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
hako-0.13.3 lib/hako/env_providers/file.rb
hako-0.13.2 lib/hako/env_providers/file.rb
hako-0.13.1 lib/hako/env_providers/file.rb
hako-0.13.0 lib/hako/env_providers/file.rb
hako-0.12.0 lib/hako/env_providers/file.rb
hako-0.11.2 lib/hako/env_providers/file.rb
hako-0.11.1 lib/hako/env_providers/file.rb
hako-0.11.0 lib/hako/env_providers/file.rb
hako-0.10.0 lib/hako/env_providers/file.rb
hako-0.9.4 lib/hako/env_providers/file.rb
hako-0.9.3 lib/hako/env_providers/file.rb
hako-0.9.2 lib/hako/env_providers/file.rb
hako-0.9.1 lib/hako/env_providers/file.rb
hako-0.9.0 lib/hako/env_providers/file.rb
hako-0.8.5 lib/hako/env_providers/file.rb
hako-0.8.4 lib/hako/env_providers/file.rb
hako-0.8.3 lib/hako/env_providers/file.rb
hako-0.8.2 lib/hako/env_providers/file.rb
hako-0.8.1 lib/hako/env_providers/file.rb
hako-0.8.0 lib/hako/env_providers/file.rb