Sha256: f7663b5e194eb9cdb64fdf4457eecc682d08784bfd96e605b3cf8d86d9ca6c88

Contents?: true

Size: 719 Bytes

Versions: 4

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

require "forwardable"
require "pathname"

module XDG
  module Paths
    # A XDG home path.
    class Home
      extend Forwardable

      KEY = "HOME"

      delegate %i[key value] => :pair

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

      def default = expand String(value)

      def dynamic = String(environment[key]).then { |path| path.empty? ? default : expand(path) }

      def inspect = [pair.key, dynamic].compact.join XDG::DELIMITER

      private

      attr_reader :pair, :environment

      def expand(path) = home.join(path).expand_path

      def home = Pathname environment.fetch(KEY)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
xdg-7.1.3 lib/xdg/paths/home.rb
xdg-7.1.2 lib/xdg/paths/home.rb
xdg-7.1.1 lib/xdg/paths/home.rb
xdg-7.1.0 lib/xdg/paths/home.rb