Sha256: ee60f419e920e5cbf9025ac3a1cf7e983a4df1b5c99f632f192a1778a5e36052

Contents?: true

Size: 727 Bytes

Versions: 18

Compression:

Stored size: 727 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::PAIR_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

18 entries across 18 versions & 1 rubygems

Version Path
xdg-6.6.2 lib/xdg/paths/home.rb
xdg-6.6.1 lib/xdg/paths/home.rb
xdg-6.6.0 lib/xdg/paths/home.rb
xdg-6.5.0 lib/xdg/paths/home.rb
xdg-6.4.0 lib/xdg/paths/home.rb
xdg-6.3.3 lib/xdg/paths/home.rb
xdg-6.3.2 lib/xdg/paths/home.rb
xdg-6.3.1 lib/xdg/paths/home.rb
xdg-6.3.0 lib/xdg/paths/home.rb
xdg-6.2.0 lib/xdg/paths/home.rb
xdg-6.1.0 lib/xdg/paths/home.rb
xdg-6.0.1 lib/xdg/paths/home.rb
xdg-6.0.0 lib/xdg/paths/home.rb
xdg-5.3.0 lib/xdg/paths/home.rb
xdg-5.2.0 lib/xdg/paths/home.rb
xdg-5.1.3 lib/xdg/paths/home.rb
xdg-5.1.2 lib/xdg/paths/home.rb
xdg-5.1.1 lib/xdg/paths/home.rb