Sha256: 2e343703777cd432fd12e2ce5305f39518ba2cc0ceffce9c8483853fe8d9b56c

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'xdg'

module XDG

  # Access to resource locations.
  #
  #   XDG.resource.each{ |dir| ... }
  #
  def resource(*glob_and_flags, &block)
    if !glob_and_flags.empty? or block_given?
      Resource.select(*glob_and_flags, &block)
    else
      Resource
    end
  end

  # = USER RESOURCES
  #
  module Resource
    include Common

    # Location of personal resource directory.
    def home
      @home ||= (
        File.expand_path(
          ENV['XDG_RESOURCE_HOME'] || File.join(XDG.home, '.local')
        )
      )
    end

    # List of common user directores.
    def dirs
      @dirs ||= (
        dirs = ENV['XDG_RESOURCE_DIRS'].split(/[:;]/)
        if dirs.empty?
          dirs = ['/usr/local', '/usr']
        end
        dirs = dirs.map{ |d| File.expand_path(d) }.uniq
        dirs = dirs.select{ |d| File.directory?(d) }
        dirs
      )
    end

    extend self
  end

  module Config

    # Location of working config directory.
    #
    # This is not not strictly XDG spec, but it
    # can be useful in an analogous respect.
    #
    def work
      @work ||= (
        File.expand_path(
          File.join(Dir.pwd, '.config')
        )
      )
    end

  end

  module Cache

    # Location of working cache directory.
    #
    # This is not strictly XDG spec, but it
    # can be useful in an analogous respect.
    #
    def work
      @work ||= (
        File.expand_path(
          File.join(Dir.pwd, '.cache')
        )
      )
    end

  end

end

# Copyright (c) 2008,2009 Thomas Sawyer
# Distributed under the terms of the LGPL v3.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xdg-1.0.0 lib/xdg/extended.rb