class XDG::Paths::Directory

A collection of XDG directories.

Constants

DELIMITER

Public Class Methods

new(pair, environment = ENV) click to toggle source
# File lib/xdg/paths/directory.rb, line 11
def initialize pair, environment = ENV
  @pair = pair
  @environment = environment
end

Public Instance Methods

default(= value.split(DELIMITER).map { |path| expand path }) click to toggle source
# File lib/xdg/paths/directory.rb, line 16
  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 to_s = [key, dynamic.join(DELIMITER)].reject(&:empty?).join XDG::DELIMITER

  alias to_str to_s

  def inspect
    pairs = to_s
    type = self.class

    pairs.empty? ? "#<#{type}:#{object_id}>" : "#<#{type}:#{object_id} #{self}>"
  end

  private

  attr_reader :pair, :environment

  def key = String pair.key

  def value = String pair.value

  def expand(path) = Pathname(path).expand_path
end
dynamic() click to toggle source
# File lib/xdg/paths/directory.rb, line 18
def dynamic
  String(environment[key]).then { |env_value| env_value.empty? ? value : env_value }
                          .split(DELIMITER)
                          .uniq
                          .map { |path| expand path }
end
expand(path) click to toggle source
# File lib/xdg/paths/directory.rb, line 44
  def expand(path) = Pathname(path).expand_path
end
inspect() click to toggle source
# File lib/xdg/paths/directory.rb, line 29
def inspect
  pairs = to_s
  type = self.class

  pairs.empty? ? "#<#{type}:#{object_id}>" : "#<#{type}:#{object_id} #{self}>"
end
key(= String pair.key) click to toggle source
# File lib/xdg/paths/directory.rb, line 40
      def key = String pair.key

      def value = String pair.value

      def expand(path) = Pathname(path).expand_path
    end
  end
end
to_s(= [key, dynamic.join(DELIMITER)].reject(&:empty?).join XDG::DELIMITER) click to toggle source
# File lib/xdg/paths/directory.rb, line 25
    def to_s = [key, dynamic.join(DELIMITER)].reject(&:empty?).join XDG::DELIMITER

    alias to_str to_s

    def inspect
      pairs = to_s
      type = self.class

      pairs.empty? ? "#<#{type}:#{object_id}>" : "#<#{type}:#{object_id} #{self}>"
    end

    private

    attr_reader :pair, :environment

    def key = String pair.key

    def value = String pair.value

    def expand(path) = Pathname(path).expand_path
  end
end
value(= String pair.value) click to toggle source
# File lib/xdg/paths/directory.rb, line 42
    def value = String pair.value

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