Module: Ego::Filesystem

Defined in:
lib/ego/filesystem.rb

Overview

Provides utility methods for getting configuration, data, and cache paths.

Constant Summary collapse

PLUGIN_GLOB =

Glob pattern for matching plug-in files

'plugins/*.rb'
BASENAME =

XDG subdirectoy name

'ego'
XDG_CACHE_HOME =

Value of $XDG_CACHE_HOME or fallback if not set

ENV['XDG_CACHE_HOME'] || File.expand_path('~/.cache')
XDG_CONFIG_HOME =

Value of $XDG_CONFIG_HOME or fallback if not set

ENV['XDG_CONFIG_HOME'] || File.expand_path('~/.config')
XDG_DATA_HOME =

Value of $XDG_DATA_HOME or fallback if not set

ENV['XDG_DATA_HOME'] || File.expand_path('~/.local/share')

Class Method Summary collapse

Class Method Details

.builtin_pluginsArray

Returns all built-in plug-in paths.

Returns:

  • (Array)

    all built-in plug-in paths

See Also:



51
52
53
# File 'lib/ego/filesystem.rb', line 51

def builtin_plugins
  Dir[File.expand_path(PLUGIN_GLOB, __dir__)]
end

.cache(path = '') ⇒ String

Returns the path to cache directory with path appended.

Parameters:

  • path (String) (defaults to: '')

    path to append

Returns:

  • (String)

    the path to cache directory with path appended

See Also:



26
27
28
# File 'lib/ego/filesystem.rb', line 26

def cache(path = '')
  File.join(XDG_CACHE_HOME, BASENAME, path)
end

.config(path = '') ⇒ String

Returns the path to config directory with path appended.

Parameters:

  • path (String) (defaults to: '')

    path to append

Returns:

  • (String)

    the path to config directory with path appended

See Also:



35
36
37
# File 'lib/ego/filesystem.rb', line 35

def config(path = '')
  File.join(XDG_CONFIG_HOME, BASENAME, path)
end

.data(path = '') ⇒ String

Returns the path to data directory with path appended.

Parameters:

  • path (String) (defaults to: '')

    path to append

Returns:

  • (String)

    the path to data directory with path appended

See Also:



44
45
46
# File 'lib/ego/filesystem.rb', line 44

def data(path = '')
  File.join(XDG_DATA_HOME, BASENAME, path)
end

.user_pluginsArray

Returns all user plug-in paths.

Returns:

  • (Array)

    all user plug-in paths

See Also:



58
59
60
# File 'lib/ego/filesystem.rb', line 58

def user_plugins
  Dir[File.expand_path(PLUGIN_GLOB, config)]
end