Sha256: 9cba2c63305d1d173f95ecad58e28be9913eb728b2ad02e5742b0922da496aaa

Contents?: true

Size: 901 Bytes

Versions: 3

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

require "forwardable"
require "refinements/pathnames"

module Runcom
  module Paths
    # Provides common path/functionality for all XDG enhanced objects.
    class Common
      extend Forwardable

      using Refinements::Pathnames

      delegate %i[inspect] => :xdg

      attr_reader :relative

      def initialize relative, context: Context.new
        @relative = Pathname relative
        @context = context
      end

      def namespace = relative.parent

      def file_name = relative.basename

      def active = all.select(&:file?).find(&:exist?)

      def passive = active || global

      def global
        all.tap { |paths| paths.delete local }
           .first
      end

      def local = all.first

      def all = xdg.all.map { |root| root.join relative }

      private

      attr_reader :context

      def xdg = context.xdg
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
runcom-10.2.1 lib/runcom/paths/common.rb
runcom-10.2.0 lib/runcom/paths/common.rb
runcom-10.1.0 lib/runcom/paths/common.rb