Sha256: 7712691d2be87cc0ad28246db53dd9d06fdbb487cdc3c79930ab467c7cf97d8b

Contents?: true

Size: 662 Bytes

Versions: 5

Compression:

Stored size: 662 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 do |path|
          File.exist?(path) ? Pathname(path).expand_path : standard.dynamic
        end
      end

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

      private

      attr_reader :standard
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
runcom-7.3.0 lib/runcom/paths/home.rb
runcom-7.2.0 lib/runcom/paths/home.rb
runcom-7.1.3 lib/runcom/paths/home.rb
runcom-7.1.2 lib/runcom/paths/home.rb
runcom-7.1.1 lib/runcom/paths/home.rb