Sha256: 75b990a3fa068584bc97971020e7a8f787cc3b23cf6a0be5b5c1924fedc126f6

Contents?: true

Size: 677 Bytes

Versions: 3

Compression:

Stored size: 677 Bytes

Contents

# frozen_string_literal: true

require "forwardable"
require "pathname"

module Runcom
  module Paths
    # A XDG home path that prefers local over global path.
    class Home
      extend Forwardable

      delegate %i[key value default] => :standard

      def initialize pair, environment = ENV
        @standard = XDG::Paths::Home.new pair, environment
      end

      def dynamic
        String(value).then { |path| Pathname path }
                     .then { |path| path.exist? ? path.expand_path : standard.dynamic }
      end

      def inspect = [standard.key, dynamic].compact.join(XDG::PAIR_DELIMITER)

      private

      attr_reader :standard
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
runcom-8.1.0 lib/runcom/paths/home.rb
runcom-8.0.1 lib/runcom/paths/home.rb
runcom-8.0.0 lib/runcom/paths/home.rb