loading
Generated 2025-10-09T00:00:39+00:00

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% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line Branch Coverage Branches Covered branches Missed branches
lib/runcom.rb 100.00 % 17 9 9 0 1.33 100.00 % 0 0 0
lib/runcom/cache.rb 100.00 % 25 12 12 0 2.83 100.00 % 0 0 0
lib/runcom/config.rb 100.00 % 25 12 12 0 2.83 100.00 % 0 0 0
lib/runcom/context.rb 100.00 % 11 5 5 0 33.00 100.00 % 2 2 0
lib/runcom/data.rb 100.00 % 25 12 12 0 2.83 100.00 % 0 0 0
lib/runcom/paths/common.rb 100.00 % 49 24 24 0 18.29 100.00 % 0 0 0
lib/runcom/paths/home.rb 100.00 % 37 19 19 0 22.68 100.00 % 0 0 0
lib/runcom/state.rb 100.00 % 25 12 12 0 2.83 100.00 % 0 0 0

lib/runcom.rb

100.0% lines covered

100.0% branches covered

9 relevant lines. 9 lines covered and 0 lines missed.
0 total branches, 0 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 require "xdg"
  3. 1 require "zeitwerk"
  4. 1 Zeitwerk::Loader.new.then do |loader|
  5. 1 loader.tag = File.basename __FILE__, ".rb"
  6. 1 loader.push_dir __dir__
  7. 1 loader.setup
  8. end
  9. # Main namespace.
  10. 1 module Runcom
  11. 1 def self.loader registry = Zeitwerk::Registry
  12. 4 @loader ||= registry.loaders.each.find { |loader| loader.tag == File.basename(__FILE__, ".rb") }
  13. end
  14. end

lib/runcom/cache.rb

100.0% lines covered

100.0% branches covered

12 relevant lines. 12 lines covered and 0 lines missed.
0 total branches, 0 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 require "forwardable"
  3. 1 module Runcom
  4. # A developer friendly wrapper of XDG cache.
  5. 1 class Cache
  6. 1 extend Forwardable
  7. 1 CONTEXT = Context.new xdg: XDG::Cache
  8. 1 delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
  9. 1 def initialize path, context: CONTEXT
  10. 12 @common = Paths::Common.new(path, context:)
  11. 12 freeze
  12. end
  13. 1 def inspect = "#<#{self.class}:#{object_id} #{common}>"
  14. 1 private
  15. 1 attr_reader :common
  16. end
  17. end

lib/runcom/config.rb

100.0% lines covered

100.0% branches covered

12 relevant lines. 12 lines covered and 0 lines missed.
0 total branches, 0 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 require "forwardable"
  3. 1 module Runcom
  4. # A developer friendly wrapper of XDG config.
  5. 1 class Config
  6. 1 extend Forwardable
  7. 1 CONTEXT = Context.new xdg: XDG::Config
  8. 1 delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
  9. 1 def initialize path, context: CONTEXT
  10. 12 @common = Paths::Common.new(path, context:)
  11. 12 freeze
  12. end
  13. 1 def inspect = "#<#{self.class}:#{object_id} #{common}>"
  14. 1 private
  15. 1 attr_reader :common
  16. end
  17. end

lib/runcom/context.rb

100.0% lines covered

100.0% branches covered

5 relevant lines. 5 lines covered and 0 lines missed.
2 total branches, 2 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 module Runcom
  3. # A common context for all XDG custom objects.
  4. 1 Context = ::Data.define :home, :environment, :xdg do
  5. 1 def initialize home: Paths::Home, environment: ENV, xdg: nil
  6. 81 then: 78 else: 3 computed_xdg = xdg.is_a?(Class) ? xdg.new(home:, environment:) : xdg
  7. 81 super home:, environment:, xdg: computed_xdg
  8. end
  9. end
  10. end

lib/runcom/data.rb

100.0% lines covered

100.0% branches covered

12 relevant lines. 12 lines covered and 0 lines missed.
0 total branches, 0 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 require "forwardable"
  3. 1 module Runcom
  4. # A developer friendly wrapper of XDG data.
  5. 1 class Data
  6. 1 extend Forwardable
  7. 1 CONTEXT = Context.new xdg: XDG::Data
  8. 1 delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
  9. 1 def initialize path, context: CONTEXT
  10. 12 @common = Paths::Common.new(path, context:)
  11. 12 freeze
  12. end
  13. 1 def inspect = "#<#{self.class}:#{object_id} #{common}>"
  14. 1 private
  15. 1 attr_reader :common
  16. end
  17. end

lib/runcom/paths/common.rb

100.0% lines covered

100.0% branches covered

24 relevant lines. 24 lines covered and 0 lines missed.
0 total branches, 0 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 require "refinements/pathname"
  3. 1 module Runcom
  4. 1 module Paths
  5. # Provides common path/functionality for all XDG enhanced objects.
  6. 1 class Common
  7. 1 using Refinements::Pathname
  8. 1 attr_reader :initial
  9. 1 def initialize initial, context: Context.new
  10. 73 @initial = Pathname initial
  11. 73 @context = context
  12. 73 freeze
  13. end
  14. 1 def namespace = initial.parent
  15. 1 def file_name = initial.basename
  16. 1 def active = all.select(&:file?).find(&:exist?)
  17. 1 def passive = active || global
  18. 1 def global
  19. 24 all.tap { |paths| paths.delete local }
  20. .first
  21. end
  22. 1 def local = all.first
  23. 177 def all = xdg.all.map { |root| root.join initial }
  24. 1 def to_s = xdg.to_s
  25. 1 alias to_str to_s
  26. 1 def inspect = "#<#{self.class}:#{object_id} #{xdg}>"
  27. 1 private
  28. 1 attr_reader :context
  29. 1 def xdg = context.xdg
  30. end
  31. end
  32. end

lib/runcom/paths/home.rb

100.0% lines covered

100.0% branches covered

19 relevant lines. 19 lines covered and 0 lines missed.
0 total branches, 0 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 require "forwardable"
  3. 1 require "pathname"
  4. 1 module Runcom
  5. 1 module Paths
  6. # A XDG home path that prefers local over global path.
  7. 1 class Home
  8. 1 extend Forwardable
  9. 1 delegate %i[key value default] => :standard
  10. 1 def initialize pair, environment = ENV
  11. 88 @standard = XDG::Paths::Home.new pair, environment
  12. 88 freeze
  13. end
  14. 1 def dynamic
  15. 148 String(value).then { |path| Pathname path }
  16. 74 .then { |path| [path.expand_path, standard.dynamic] }
  17. end
  18. 1 def to_s
  19. 19 [standard.key, dynamic.join(XDG::Paths::Directory::DELIMITER)].compact.join XDG::DELIMITER
  20. end
  21. 1 alias to_str to_s
  22. 1 def inspect = "#<#{self.class}:#{object_id} #{self}>"
  23. 1 private
  24. 1 attr_reader :standard
  25. end
  26. end
  27. end

lib/runcom/state.rb

100.0% lines covered

100.0% branches covered

12 relevant lines. 12 lines covered and 0 lines missed.
0 total branches, 0 branches covered and 0 branches missed.
    
  1. # frozen_string_literal: true
  2. 1 require "forwardable"
  3. 1 module Runcom
  4. # A developer friendly wrapper of XDG state.
  5. 1 class State
  6. 1 extend Forwardable
  7. 1 CONTEXT = Context.new xdg: XDG::State
  8. 1 delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
  9. 1 def initialize path, context: CONTEXT
  10. 12 @common = Paths::Common.new(path, context:)
  11. 12 freeze
  12. end
  13. 1 def inspect = "#<#{self.class}:#{object_id} #{common}>"
  14. 1 private
  15. 1 attr_reader :common
  16. end
  17. end