Sha256: 3f7755bcc831cb568ef8cd56c29e2f4f1c92e0b55750a4576bd203a9928c6540

Contents?: true

Size: 739 Bytes

Versions: 4

Compression:

Stored size: 739 Bytes

Contents

# frozen_string_literal: true

require "forwardable"
require "pathname"

module Runcom
  module Paths
    # A XDG home path with a strict adherence to the XDG specification.
    class Standard
      extend Forwardable

      HOME_KEY = "HOME"

      delegate %i[key value] => :pair

      def initialize pair, environment = ENV
        @pair = pair
        @environment = environment
      end

      def default
        home.join(String(value)).expand_path
      end

      def dynamic
        path = String environment[key]
        path.empty? ? default : home.join(path).expand_path
      end

      private

      attr_reader :pair, :environment

      def home
        Pathname environment.fetch(HOME_KEY)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
runcom-4.2.1 lib/runcom/paths/standard.rb
runcom-4.2.0 lib/runcom/paths/standard.rb
runcom-4.1.0 lib/runcom/paths/standard.rb
runcom-4.0.0 lib/runcom/paths/standard.rb