runcom 10.2.1 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b36f55daf5e33ad0b28c4a085b7eb52e3cfe0b7410680f3b73aed9df614c8aa3
4
- data.tar.gz: af8e20a01d052c2adacb048b33e278a464c647eff4834c76a0df8a93d874e648
3
+ metadata.gz: 0feaa12d363465346d2ea56a8bdcdaba2ec353ebb1235a17cdc8ed38fe2a25da
4
+ data.tar.gz: '061918ad4c3d1806e42093a3e0ee4ec2e1f5b28cefad2ceb74664e77f7693f3b'
5
5
  SHA512:
6
- metadata.gz: 6a4b6f740b7d74fac97d83fce62048dda898f543c21e191438a071e79cdd56987f684543630214357e2903c189ee78cda5a6b8688f64c8035779501085a1c80e
7
- data.tar.gz: 2db839bfd2b1674a115177360ef8fbfaabb8c782f3069b0c43bd732081ccd3368c9a638c6cdc131b2acd41a2ecfbeba7200d6612989bf51f19ee061e0355085d
6
+ metadata.gz: 901d5075cd8ac4864120c397f8a245507ee192e9cd3f7b56ceaee161d6d553bc9688886cd3a9312b7ab65e132175701df4a8b4eda77e10e2be7ae0f655f6783b
7
+ data.tar.gz: 6f567a1ce2fd1855606acaf40bec452ebde5cc4e06254737cfbff93cb490f1ba9e5a0252ce0e3ec29c92a6418704470f3600ac1f0add5bc0096379b2209a99c2
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -7,21 +7,20 @@
7
7
 
8
8
  = Runcom
9
9
 
10
- Runcom is a link:https://en.wikipedia.org/wiki/Run_commands[Run Command] portmanteau (i.e. `run + [com]mand = runcom`) which provides common functionality for Command Line Interfaces (CLIs) in which to manage global/local caches, configurations, data, and/or state. It does this by leveraging the https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html[XDG Base Directory Specification] built atop the {xdg_link} implementation. In other words, Runcom is an enhanced version of {xdg_link}.
10
+ Runcom is a link:https://en.wikipedia.org/wiki/Run_commands[Run Command] portmanteau (i.e. `run + [com]mand = runcom`) which provides common functionality for Command Line Interfaces (CLIs) in which to manage global/local caches, configurations, data, and/or state. This is done by leveraging the https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html[XDG Base Directory Specification] built atop the {xdg_link} implementation. In other words, Runcom is an enhanced version of {xdg_link} which specializes in dynamic global and local detection.
11
11
 
12
12
  toc::[]
13
13
 
14
14
  == Features
15
15
 
16
- * Wraps the {xdg_link} implementation which provides access to
17
- the following environment variables:
16
+ * Wraps the {xdg_link} implementation which provides access to the following environment variables:
18
17
  ** `+$XDG_CACHE_HOME+`
19
18
  ** `+$XDG_CONFIG_HOME+`
20
19
  ** `+$XDG_CONFIG_DIRS+`
21
20
  ** `+$XDG_DATA_HOME+`
22
21
  ** `+$XDG_DATA_DIRS+`
23
22
  ** `+$XDG_STATE_HOME+`
24
- * Enhances the {xdg_link} cache, config, data, and state implementations.
23
+ * Enhances the {xdg_link} cache, config, data, and state implementations with dynamic global and local detection.
25
24
 
26
25
  == Requirements
27
26
 
@@ -65,7 +64,7 @@ The following describes the enhancements built atop the {xdg_link} implementatio
65
64
 
66
65
  === Overview
67
66
 
68
- While there isn’t an environment convenience object as found with the `XDG` gem, you can instantiate each object individually:
67
+ While there isn’t a sole convenience object as found with the `XDG` gem, you can instantiate each object individually:
69
68
 
70
69
  [source,ruby]
71
70
  ----
@@ -75,46 +74,102 @@ data = Runcom::Data.new "demo/store.dat"
75
74
  state = Runcom::State.new "demo/history.log"
76
75
  ----
77
76
 
78
- 💡 By default, each Runcom object expects a relative path but you can use a fully qualified path as well.
77
+ By default, each Runcom object expects a relative file path but you can also use a fully qualified path when constructing a new instance.
79
78
 
80
79
  Each of the above objects share the same Object API:
81
80
 
82
- * `#relative`: Answers the relative path from which the object was constructed.
81
+ * `#initial`: Answers the initial path -- which can be a relative or absolute path -- from which the object was constructed.
83
82
  * `#namespace`: Answers the namespace as a pathname object from which the instance was constructed. The namespace must be unique and identical across the cache, config, data, and state objects since this is what identifies and organizes all files associated with your program.
84
83
  * `#file_name`: Answers the file name from which the object was constructed.
85
84
  * `#active`: Answers first _existing file path_ as computed by `+$XDG_*_HOME+` followed by each computed `+$XDG_*_DIRS+` path in order defined. Otherwise, `nil` is answered back when no path exists.
86
85
  * `#passive`: Answers first path as computed by `+$XDG_*_HOME+` followed by each computed `+$XDG_*_DIRS+` path in order defined which _may_ or _may not_ exist. This behaves like `#active` but doesn't care if the path exists. Handy for situations where you'd like the active path but can fallback to creating the global path if otherwise.
87
- * `#global`: Answers the first _existing_ or _non-existing_ global path only.
88
- * `#local`: Answers the first _existing_ or _non-existing_ local path only.
86
+ * `#global`: Answers the first _existing_ or _non-existing_ global path.
87
+ * `#local`: Answers the first _existing_ or _non-existing_ local path.
89
88
  * `#all`: Answers all paths which is the combined `+$XDG_*_HOME+` and `+$XDG_*_DIRS+` values in order defined. These paths _may_ or _may not_ exist.
90
- * `#inspect`: Answers a string representation of default XDG home and directory paths for debugging purposes.
89
+ * `#to_s`: Answers an _explicit_ string cast for the current environment.
90
+ * `#to_str`: Answers an _implicit_ string cast for the current environment.
91
+ * `#inspect`: Answers object inspection complete with object type, object ID, and all environment variables.
91
92
 
92
- Using a `cache` object, for example, here is what each method answers back:
93
+ === Examples
94
+
95
+ The following are examples of what you will see when exploring the Runcom objects within an IRB console:
93
96
 
94
97
  [source,ruby]
95
98
  ----
96
- cache = Runcom::Cache.new "demo/content.json"
97
-
98
- cache.relative # => #<Pathname:demo/content.json>
99
- cache.namespace # #<Pathname:demo>
100
- cache.file_name # #<Pathname:content.json>
101
- cache.active # nil
102
- cache.passive # #<Pathname:/Users/demo/.cache/demo/content.json>
103
- cache.global # #<Pathname:/Users/demo/.cache/demo/content.json>
104
- cache.local # #<Pathname:/Users/demo/Engineering/OSS/runcom/.cache/demo/content.json>
105
- cache.all # [#<Pathname:/Users/demo/Engineering/OSS/runcom/.cache/demo/content.json>, #<Pathname:/Users/demo/.cache/demo/content.json>]
106
- cache.inspect # "XDG_CACHE_HOME=/Users/demo/Engineering/OSS/runcom/.cache:/Users/demo/.cache"
99
+ # Initialization
100
+
101
+ cache = XDG::Cache.new "demo/projects.json"
102
+ config = XDG::Config.new "demo/settings.yml"
103
+ data = XDG::Data.new "demo/vault.store"
104
+ state = XDG::State.new "demo/history.log"
105
+
106
+ # Paths
107
+
108
+ cache.initial # "#<Pathname:demo/projects.json>"
109
+ cache.namespace # "#<Pathname:demo>"
110
+ cache.file_name # "#<Pathname:projects.json>"
111
+ cache.active # nil
112
+ cache.passive # "#<Pathname:/Users/demo/.cache/demo/projects.json>"
113
+ cache.global # "#<Pathname:/Users/demo/.cache/demo/projects.json>"
114
+ cache.local # "#<Pathname:/Users/demo/Engineering/OSS/runcom/.cache/demo/projects.json>"
115
+ cache.all # ["#<Pathname:/Users/demo/Engineering/OSS/runcom/.cache/demo/projects.json>", "#<Pathname:/Users/demo/.cache/demo/projects.json>"]
116
+
117
+ config.initial # "#<Pathname:demo/settings.yml>"
118
+ config.namespace # "#<Pathname:demo>"
119
+ config.file_name # "#<Pathname:settings.yml>"
120
+ config.active # nil
121
+ config.passive # "#<Pathname:/Users/demo/.config/demo/settings.yml>"
122
+ config.global # "#<Pathname:/Users/demo/.config/demo/settings.yml>"
123
+ config.local # "#<Pathname:/Users/demo/Engineering/OSS/runcom/.config/demo/settings.yml>"
124
+ config.all # ["#<Pathname:/Users/demo/Engineering/OSS/runcom/.config/demo/settings.yml>", "#<Pathname:/Users/demo/.config/demo/settings.yml>", "#<Pathname:/etc/xdg/demo/settings.yml>"]
125
+
126
+ data.initial # "#<Pathname:demo/vault.store>"
127
+ data.namespace # "#<Pathname:demo>"
128
+ data.file_name # "#<Pathname:vault.store>"
129
+ data.active # nil
130
+ data.passive # "#<Pathname:/Users/demo/.local/share/demo/vault.store>"
131
+ data.global # "#<Pathname:/Users/demo/.local/share/demo/vault.store>"
132
+ data.local # "#<Pathname:/Users/demo/Engineering/OSS/runcom/.local/share/demo/vault.store>"
133
+ data.all # ["#<Pathname:/Users/demo/Engineering/OSS/runcom/.local/share/demo/vault.store>", "#<Pathname:/Users/demo/.local/share/demo/vault.store>", "#<Pathname:/usr/local/share/demo/vault.store>", "#<Pathname:/usr/share/demo/vault.store>"]
134
+
135
+ state.initial # "#<Pathname:demo/history.log>"
136
+ state.namespace # "#<Pathname:demo>"
137
+ state.file_name # "#<Pathname:history.log>"
138
+ state.active # nil
139
+ state.passive # "#<Pathname:/Users/demo/.local/state/demo/history.log>"
140
+ state.global # "#<Pathname:/Users/demo/.local/state/demo/history.log>"
141
+ state.local # "#<Pathname:/Users/demo/Engineering/OSS/runcom/.local/state/demo/history.log>"
142
+ state.all # ["#<Pathname:/Users/demo/Engineering/OSS/runcom/.local/state/demo/history.log>", "#<Pathname:/Users/demo/.local/state/demo/history.log>"]
143
+
144
+ # Casts (explicit and implicit)
145
+
146
+ cache.to_s # "XDG_CACHE_HOME=/Users/demo/Engineering/OSS/runcom/.cache:/Users/demo/.cache"
147
+ config.to_s # "XDG_CONFIG_HOME=/Users/demo/Engineering/OSS/runcom/.config:/Users/demo/.config XDG_CONFIG_DIRS=/etc/xdg"
148
+ data.to_s # "XDG_DATA_HOME=/Users/demo/Engineering/OSS/runcom/.local/share:/Users/demo/.local/share XDG_DATA_DIRS=/usr/local/share:/usr/share"
149
+ state.to_s # "XDG_STATE_HOME=/Users/demo/Engineering/OSS/runcom/.local/state:/Users/demo/.local/state"
150
+
151
+ cache.to_str # "XDG_CACHE_HOME=/Users/demo/Engineering/OSS/runcom/.cache:/Users/demo/.cache"
152
+ config.to_str # "XDG_CONFIG_HOME=/Users/demo/Engineering/OSS/runcom/.config:/Users/demo/.config XDG_CONFIG_DIRS=/etc/xdg"
153
+ data.to_str # "XDG_DATA_HOME=/Users/demo/Engineering/OSS/runcom/.local/share:/Users/demo/.local/share XDG_DATA_DIRS=/usr/local/share:/usr/share"
154
+ state.to_str # "XDG_STATE_HOME=/Users/demo/Engineering/OSS/runcom/.local/state:/Users/demo/.local/state"
155
+
156
+ # Inspection
157
+
158
+ cache.inspect # "#<Runcom::Cache:2040 XDG_CACHE_HOME=/Users/demo/Engineering/OSS/runcom/.cache:/Users/demo/.cache>"
159
+ config.inspect # "#<Runcom::Config:2060 XDG_CONFIG_HOME=/Users/demo/Engineering/OSS/runcom/.config:/Users/demo/.config XDG_CONFIG_DIRS=/etc/xdg>"
160
+ data.inspect # "#<Runcom::Data:2080 XDG_DATA_HOME=/Users/demo/Engineering/OSS/runcom/.local/share:/Users/demo/.local/share XDG_DATA_DIRS=/usr/local/share:/usr/share>"
161
+ state.inspect # "#<Runcom::State:2100 XDG_STATE_HOME=/Users/demo/Engineering/OSS/runcom/.local/state:/Users/demo/.local/state>"
107
162
  ----
108
163
 
109
164
  === Variable Priority
110
165
 
111
166
  Path precedence is determined in the following order (with the first taking highest priority):
112
167
 
113
- . *Local Configuration* - If a `+$XDG_*_HOME+` or `+$XDG_*_DIRS+` path relative to the
168
+ . *Local Configuration*: If a `+$XDG_*_HOME+` or `+$XDG_*_DIRS+` path relative to the
114
169
  current working directory is detected, it will take precedence over the global configuration.
115
170
  This is the same behavior as found in Git where the local `.git/config` takes precedence over the
116
171
  global `$HOME/.gitconfig`.
117
- . *Global Configuration* - When a local configuration isn’t found, the global configuration is used
172
+ . *Global Configuration*: When a local configuration isn’t found, the global configuration is used
118
173
  as defined by the _XDG Base Directory Specification_.
119
174
 
120
175
  === Building Blocks
@@ -160,6 +215,13 @@ You can also use the IRB console for direct access to all objects:
160
215
  bin/console
161
216
  ----
162
217
 
218
+ Lastly, there is a `bin/demo` script which displays default functionality for quick visual reference. This is the same script used to generate the usage examples shown at the top of this document.
219
+
220
+ [source,bash]
221
+ ----
222
+ bin/demo
223
+ ----
224
+
163
225
  == Tests
164
226
 
165
227
  To test, run:
data/lib/runcom/cache.rb CHANGED
@@ -9,12 +9,14 @@ module Runcom
9
9
 
10
10
  CONTEXT = Context.new xdg: XDG::Cache
11
11
 
12
- delegate %i[relative namespace file_name active passive global local all inspect] => :common
12
+ delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
13
13
 
14
14
  def initialize path, context: CONTEXT
15
15
  @common = Paths::Common.new path, context:
16
16
  end
17
17
 
18
+ def inspect = "#<#{self.class}:#{object_id} #{common}>"
19
+
18
20
  private
19
21
 
20
22
  attr_reader :common
data/lib/runcom/config.rb CHANGED
@@ -9,12 +9,14 @@ module Runcom
9
9
 
10
10
  CONTEXT = Context.new xdg: XDG::Config
11
11
 
12
- delegate %i[relative namespace file_name active passive global local all inspect] => :common
12
+ delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
13
13
 
14
14
  def initialize path, context: CONTEXT
15
15
  @common = Paths::Common.new path, context:
16
16
  end
17
17
 
18
+ def inspect = "#<#{self.class}:#{object_id} #{common}>"
19
+
18
20
  private
19
21
 
20
22
  attr_reader :common
@@ -2,15 +2,10 @@
2
2
 
3
3
  module Runcom
4
4
  # A common context for all XDG custom objects.
5
- Context = Struct.new :home, :environment, :xdg do
6
- def initialize(**)
7
- super
8
-
9
- self[:home] ||= Paths::Home
10
- self[:environment] ||= ENV
11
- self[:xdg] = xdg.new(home:, environment:) if xdg
12
-
13
- freeze
5
+ Context = ::Data.define :home, :environment, :xdg do
6
+ def initialize home: Paths::Home, environment: ENV, xdg: nil
7
+ computed_xdg = xdg.is_a?(Class) ? xdg.new(home:, environment:) : xdg
8
+ super home:, environment:, xdg: computed_xdg
14
9
  end
15
10
  end
16
11
  end
data/lib/runcom/data.rb CHANGED
@@ -9,12 +9,14 @@ module Runcom
9
9
 
10
10
  CONTEXT = Context.new xdg: XDG::Data
11
11
 
12
- delegate %i[relative namespace file_name active passive global local all inspect] => :common
12
+ delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
13
13
 
14
14
  def initialize path, context: CONTEXT
15
15
  @common = Paths::Common.new path, context:
16
16
  end
17
17
 
18
+ def inspect = "#<#{self.class}:#{object_id} #{common}>"
19
+
18
20
  private
19
21
 
20
22
  attr_reader :common
@@ -1,28 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "forwardable"
4
- require "refinements/pathnames"
3
+ require "refinements/pathname"
5
4
 
6
5
  module Runcom
7
6
  module Paths
8
7
  # Provides common path/functionality for all XDG enhanced objects.
9
8
  class Common
10
- extend Forwardable
9
+ using Refinements::Pathname
11
10
 
12
- using Refinements::Pathnames
11
+ attr_reader :initial
13
12
 
14
- delegate %i[inspect] => :xdg
15
-
16
- attr_reader :relative
17
-
18
- def initialize relative, context: Context.new
19
- @relative = Pathname relative
13
+ def initialize initial, context: Context.new
14
+ @initial = Pathname initial
20
15
  @context = context
21
16
  end
22
17
 
23
- def namespace = relative.parent
18
+ def namespace = initial.parent
24
19
 
25
- def file_name = relative.basename
20
+ def file_name = initial.basename
26
21
 
27
22
  def active = all.select(&:file?).find(&:exist?)
28
23
 
@@ -35,7 +30,13 @@ module Runcom
35
30
 
36
31
  def local = all.first
37
32
 
38
- def all = xdg.all.map { |root| root.join relative }
33
+ def all = xdg.all.map { |root| root.join initial }
34
+
35
+ def to_s = xdg.to_s
36
+
37
+ alias to_str to_s
38
+
39
+ def inspect = "#<#{self.class}:#{object_id} #{xdg}>"
39
40
 
40
41
  private
41
42
 
@@ -20,10 +20,14 @@ module Runcom
20
20
  .then { |path| [path.expand_path, standard.dynamic] }
21
21
  end
22
22
 
23
- def inspect
23
+ def to_s
24
24
  [standard.key, dynamic.join(XDG::Paths::Directory::DELIMITER)].compact.join XDG::DELIMITER
25
25
  end
26
26
 
27
+ alias to_str to_s
28
+
29
+ def inspect = "#<#{self.class}:#{object_id} #{self}>"
30
+
27
31
  private
28
32
 
29
33
  attr_reader :standard
data/lib/runcom/state.rb CHANGED
@@ -9,12 +9,14 @@ module Runcom
9
9
 
10
10
  CONTEXT = Context.new xdg: XDG::State
11
11
 
12
- delegate %i[relative namespace file_name active passive global local all inspect] => :common
12
+ delegate %i[initial namespace file_name active passive global local all to_s to_str] => :common
13
13
 
14
14
  def initialize path, context: CONTEXT
15
15
  @common = Paths::Common.new path, context:
16
16
  end
17
17
 
18
+ def inspect = "#<#{self.class}:#{object_id} #{common}>"
19
+
18
20
  private
19
21
 
20
22
  attr_reader :common
data/runcom.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "runcom"
5
- spec.version = "10.2.1"
5
+ spec.version = "11.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/runcom"
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.signing_key = Gem.default_key_path
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
- spec.required_ruby_version = [">= 3.2", "<= 3.3"]
26
- spec.add_dependency "refinements", "~> 11.0"
27
- spec.add_dependency "xdg", "~> 7.1"
25
+ spec.required_ruby_version = "~> 3.3"
26
+ spec.add_dependency "refinements", "~> 12.0"
27
+ spec.add_dependency "xdg", "~> 8.0"
28
28
  spec.add_dependency "zeitwerk", "~> 2.6"
29
29
 
30
30
  spec.files = Dir["*.gemspec", "lib/**/*"]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runcom
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.2.1
4
+ version: 11.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-11-16 00:00:00.000000000 Z
38
+ date: 2024-01-01 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: refinements
@@ -43,28 +43,28 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '11.0'
46
+ version: '12.0'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '11.0'
53
+ version: '12.0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: xdg
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '7.1'
60
+ version: '8.0'
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '7.1'
67
+ version: '8.0'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: zeitwerk
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -117,10 +117,7 @@ require_paths:
117
117
  - lib
118
118
  required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: '3.2'
123
- - - "<="
120
+ - - "~>"
124
121
  - !ruby/object:Gem::Version
125
122
  version: '3.3'
126
123
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -129,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
126
  - !ruby/object:Gem::Version
130
127
  version: '0'
131
128
  requirements: []
132
- rubygems_version: 3.4.22
129
+ rubygems_version: 3.5.3
133
130
  signing_key:
134
131
  specification_version: 4
135
132
  summary: A XDG enhanced run command manager for command line interfaces.
metadata.gz.sig CHANGED
Binary file