Class: Runcom::Paths::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/runcom/paths/common.rb

Overview

Provides common path/functionality for all XDG enhanced objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial, context: Context.new) ⇒ Common

Returns a new instance of Common.



13
14
15
16
17
# File 'lib/runcom/paths/common.rb', line 13

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

Instance Attribute Details

#initialObject (readonly)

Returns the value of attribute initial.



11
12
13
# File 'lib/runcom/paths/common.rb', line 11

def initial
  @initial
end

Instance Method Details

#activeObject



23
# File 'lib/runcom/paths/common.rb', line 23

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

#allObject



34
# File 'lib/runcom/paths/common.rb', line 34

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

#file_nameObject



21
# File 'lib/runcom/paths/common.rb', line 21

def file_name = initial.basename

#globalObject



27
28
29
30
# File 'lib/runcom/paths/common.rb', line 27

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

#inspectObject



40
# File 'lib/runcom/paths/common.rb', line 40

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

#localObject



32
# File 'lib/runcom/paths/common.rb', line 32

def local = all.first

#namespaceObject



19
# File 'lib/runcom/paths/common.rb', line 19

def namespace = initial.parent

#passiveObject



25
# File 'lib/runcom/paths/common.rb', line 25

def passive = active || global

#to_sObject Also known as: to_str



36
# File 'lib/runcom/paths/common.rb', line 36

def to_s = xdg.to_s