All Files
(
100.0%
covered at
11.27
hits/line
)
8 files in total.
105 relevant lines,
105 lines covered and
0 lines missed.
(
100.0%
)
2 total branches,
2 branches covered and
0 branches missed.
(
100.0%
)
-
# frozen_string_literal: true
-
-
1
require "xdg"
-
1
require "zeitwerk"
-
-
1
Zeitwerk::Loader.new.then do |loader|
-
1
loader.tag = File.basename __FILE__, ".rb"
-
1
loader.push_dir __dir__
-
1
loader.setup
-
end
-
-
# Main namespace.
-
1
module Runcom
-
1
def self.loader registry = Zeitwerk::Registry
-
4
@loader ||= registry.loaders.each.find { |loader| loader.tag == File.basename(__FILE__, ".rb") }
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "forwardable"
-
-
1
module Runcom
-
# A developer friendly wrapper of XDG cache.
-
1
class Cache
-
1
extend Forwardable
-
-
1
CONTEXT = Context.new xdg: XDG::Cache
-
-
1
delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
-
-
1
def initialize path, context: CONTEXT
-
12
@common = Paths::Common.new(path, context:)
-
12
freeze
-
end
-
-
1
def inspect = "#<#{self.class}:#{object_id} #{common}>"
-
-
1
private
-
-
1
attr_reader :common
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "forwardable"
-
-
1
module Runcom
-
# A developer friendly wrapper of XDG config.
-
1
class Config
-
1
extend Forwardable
-
-
1
CONTEXT = Context.new xdg: XDG::Config
-
-
1
delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
-
-
1
def initialize path, context: CONTEXT
-
12
@common = Paths::Common.new(path, context:)
-
12
freeze
-
end
-
-
1
def inspect = "#<#{self.class}:#{object_id} #{common}>"
-
-
1
private
-
-
1
attr_reader :common
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Runcom
-
# A common context for all XDG custom objects.
-
1
Context = ::Data.define :home, :environment, :xdg do
-
1
def initialize home: Paths::Home, environment: ENV, xdg: nil
-
81
then: 78
else: 3
computed_xdg = xdg.is_a?(Class) ? xdg.new(home:, environment:) : xdg
-
81
super home:, environment:, xdg: computed_xdg
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "forwardable"
-
-
1
module Runcom
-
# A developer friendly wrapper of XDG data.
-
1
class Data
-
1
extend Forwardable
-
-
1
CONTEXT = Context.new xdg: XDG::Data
-
-
1
delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
-
-
1
def initialize path, context: CONTEXT
-
12
@common = Paths::Common.new(path, context:)
-
12
freeze
-
end
-
-
1
def inspect = "#<#{self.class}:#{object_id} #{common}>"
-
-
1
private
-
-
1
attr_reader :common
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/pathname"
-
-
1
module Runcom
-
1
module Paths
-
# Provides common path/functionality for all XDG enhanced objects.
-
1
class Common
-
1
using Refinements::Pathname
-
-
1
attr_reader :initial
-
-
1
def initialize initial, context: Context.new
-
73
@initial = Pathname initial
-
73
@context = context
-
73
freeze
-
end
-
-
1
def namespace = initial.parent
-
-
1
def file_name = initial.basename
-
-
1
def active = all.select(&:file?).find(&:exist?)
-
-
1
def passive = active || global
-
-
1
def global
-
24
all.tap { |paths| paths.delete local }
-
.first
-
end
-
-
1
def local = all.first
-
-
177
def all = xdg.all.map { |root| root.join initial }
-
-
1
def to_s = xdg.to_s
-
-
1
alias to_str to_s
-
-
1
def inspect = "#<#{self.class}:#{object_id} #{xdg}>"
-
-
1
private
-
-
1
attr_reader :context
-
-
1
def xdg = context.xdg
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "forwardable"
-
1
require "pathname"
-
-
1
module Runcom
-
1
module Paths
-
# A XDG home path that prefers local over global path.
-
1
class Home
-
1
extend Forwardable
-
-
1
delegate %i[key value default] => :standard
-
-
1
def initialize pair, environment = ENV
-
88
@standard = XDG::Paths::Home.new pair, environment
-
88
freeze
-
end
-
-
1
def dynamic
-
148
String(value).then { |path| Pathname path }
-
74
.then { |path| [path.expand_path, standard.dynamic] }
-
end
-
-
1
def to_s
-
19
[standard.key, dynamic.join(XDG::Paths::Directory::DELIMITER)].compact.join XDG::DELIMITER
-
end
-
-
1
alias to_str to_s
-
-
1
def inspect = "#<#{self.class}:#{object_id} #{self}>"
-
-
1
private
-
-
1
attr_reader :standard
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "forwardable"
-
-
1
module Runcom
-
# A developer friendly wrapper of XDG state.
-
1
class State
-
1
extend Forwardable
-
-
1
CONTEXT = Context.new xdg: XDG::State
-
-
1
delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
-
-
1
def initialize path, context: CONTEXT
-
12
@common = Paths::Common.new(path, context:)
-
12
freeze
-
end
-
-
1
def inspect = "#<#{self.class}:#{object_id} #{common}>"
-
-
1
private
-
-
1
attr_reader :common
-
end
-
end