Sha256: 9f7a4e6371a6b0967950f31a854289f4ceb2e654c8a2d20102655bdcd8e781ae

Contents?: true

Size: 901 Bytes

Versions: 18

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

require "pathname"

module XDG
  module Paths
    # A collection of XDG directories.
    class Directory
      DELIMITER = ":"

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

      def default = value.split(DELIMITER).map { |path| expand path }

      def dynamic
        String(environment[key]).then { |env_value| env_value.empty? ? value : env_value }
                                .split(DELIMITER)
                                .uniq
                                .map { |path| expand path }
      end

      def inspect = [key, dynamic.join(DELIMITER)].reject(&:empty?).join(XDG::PAIR_DELIMITER)

      private

      attr_reader :pair, :environment

      def key = String(pair.key)

      def value = String(pair.value)

      def expand(path) = Pathname(path).expand_path
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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