Sha256: 04f67b3af7c2a2f1fee632010dc802aba5d7548b06a07d9ffffad4cdd17c4c39

Contents?: true

Size: 796 Bytes

Versions: 11

Compression:

Stored size: 796 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.expand_path, standard.dynamic] }
      end

      def to_s
        [standard.key, dynamic.join(XDG::Paths::Directory::DELIMITER)].compact.join XDG::DELIMITER
      end

      alias to_str to_s

      def inspect = "#<#{self.class}:#{object_id} #{self}>"

      private

      attr_reader :standard
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
runcom-11.10.0 lib/runcom/paths/home.rb
runcom-11.9.0 lib/runcom/paths/home.rb
runcom-11.8.0 lib/runcom/paths/home.rb
runcom-11.7.0 lib/runcom/paths/home.rb
runcom-11.6.0 lib/runcom/paths/home.rb
runcom-11.5.0 lib/runcom/paths/home.rb
runcom-11.4.1 lib/runcom/paths/home.rb
runcom-11.3.0 lib/runcom/paths/home.rb
runcom-11.2.0 lib/runcom/paths/home.rb
runcom-11.1.0 lib/runcom/paths/home.rb
runcom-11.0.0 lib/runcom/paths/home.rb