runcom 9.0.2 → 10.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: 83ba4ae1fdbc3da964d59ee0b169bdfa7635d82e6e60de053c40403f03609e79
4
- data.tar.gz: f52f274e28a3649de2b3ddad1529d6f284d4c6081df62c480aac3ff3d1e831f6
3
+ metadata.gz: b8544b04b1234823a0f9edda9da1eceb5f33e945c5637d15261efa80be64d26f
4
+ data.tar.gz: ffbb52ac4c8127aa6cb81234d290d65da71099c40b6f3e389856f0878c0e47df
5
5
  SHA512:
6
- metadata.gz: c95607ba2a5ec3bdaf82829f694ccb3cb92fa09e078d301883ab24eb919561b5f23341bb960124e2bb70e16db6df5aef7e9f843662518978ea5d16a1ca9afacc
7
- data.tar.gz: 177b044277f1c3144f081395b09a1dea356c8f3dd6a21a4e6d4aed98e5f426e9d7ac472eba2c10bdeebb84745ba676243df6ee8433a6e69e2f849f4bd5077b94
6
+ metadata.gz: e0f75136a6d3a31858ae1d5876f3356e0a59b86915a3d9f982bc2465b0b14c3ce7ad6cd95473e7e3dad5f10918aa300398ef6e7d3eb72e04ab16a5a1184e283e
7
+ data.tar.gz: 2cfe9cb8e86b10cb1f98fa66cb44477a07acd9e680fe3adcb49dd743a56b711c80669bab1756ee5b111acd1fd7fbeef2833d7e40c2ad6c98dcb14d2c0adf38f9
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -2,20 +2,18 @@
2
2
  :toclevels: 5
3
3
  :figure-caption!:
4
4
 
5
+ :xdg_link: link:https://alchemists.io/projects/xdg[XDG]
6
+ :etcher_link: link:https://alchemists.io/projects/etcher[Etcher]
7
+
5
8
  = Runcom
6
9
 
7
- Runcom is a link:https://en.wikipedia.org/wiki/Run_commands[Run Command] portmanteau (i.e. `run +
8
- [com]mand = runcom`) which provides common functionality for Command Line Interfaces (CLIs) in which
9
- to manage global, local, or multiple caches, configurations, or data in general. It does this by
10
- leveraging the https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html[XDG Base
11
- Directory Specification] built atop the link:https://alchemists.io/projects/xdg[XDG]
12
- implementation. In other words, Runcom is an advanced version of XDG.
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}.
13
11
 
14
12
  toc::[]
15
13
 
16
14
  == Features
17
15
 
18
- * Wraps the link:https://alchemists.io/projects/xdg[XDG] implementation which provides access to
16
+ * Wraps the {xdg_link} implementation which provides access to
19
17
  the following environment variables:
20
18
  ** `$XDG_CACHE_HOME`
21
19
  ** `$XDG_CONFIG_HOME`
@@ -23,11 +21,7 @@ toc::[]
23
21
  ** `$XDG_DATA_HOME`
24
22
  ** `$XDG_DATA_DIRS`
25
23
  ** `$XDG_STATE_HOME`
26
- * Enhances the XDG cache, config, data, and state implementation. For the config, the following is
27
- supported:
28
- ** Supports loading of CLI-specific http://yaml.org[YAML] configuration file.
29
- ** Supports loading and merging of nested/complex configurations.
30
- ** Supports hash representation of configuration.
24
+ * Enhances the {xdg_link} cache, config, data, and state implementations.
31
25
 
32
26
  == Requirements
33
27
 
@@ -35,62 +29,84 @@ toc::[]
35
29
 
36
30
  == Setup
37
31
 
38
- To install, run:
32
+ To install _with_ security, run:
33
+
34
+ [source,bash]
35
+ ----
36
+ # 💡 Skip this line if you already have the public certificate installed.
37
+ gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
38
+ gem install runcom --trust-policy HighSecurity
39
+ ----
40
+
41
+ To install _without_ security, run:
39
42
 
40
43
  [source,bash]
41
44
  ----
42
45
  gem install runcom
43
46
  ----
44
47
 
45
- Add the following to your Gemfile:
48
+ You can also add the gem directly to your project:
49
+
50
+ [source,bash]
51
+ ----
52
+ bundle add runcom
53
+ ----
54
+
55
+ Once the gem is installed, you only need to require it:
46
56
 
47
57
  [source,ruby]
48
58
  ----
49
- gem "runcom"
59
+ require "runcom"
50
60
  ----
51
61
 
52
62
  == Usage
53
63
 
54
- The following describes the enhancements built atop the
55
- link:https://alchemists.io/projects/xdg[XDG] implementation.
64
+ The following describes the enhancements built atop the {xdg_link} implementation.
56
65
 
57
66
  === Overview
58
67
 
59
- While there isn’t an environment convenience object as found in the `+XDG+` namespace, you can
60
- instantiate each object individually:
68
+ While there isn’t an environment convenience object as found with the `XDG` gem, you can instantiate each object individually:
61
69
 
62
70
  [source,ruby]
63
71
  ----
64
- cache = Runcom::Cache.new "example/data.json"
65
- config = Runcom::Config.new "example/configuration.yml"
66
- data = Runcom::Data.new "example/store.dat"
67
- state = Runcom::State.new "example/history.log"
72
+ cache = Runcom::Cache.new "demo/data.json"
73
+ config = Runcom::Config.new "demo/configuration.yml"
74
+ data = Runcom::Data.new "demo/store.dat"
75
+ state = Runcom::State.new "demo/history.log"
68
76
  ----
69
77
 
70
- Each of the above objects share the same API:
78
+ 💡 By default, each Runcom object expects a relative path but you can use a fully qualified path as well.
71
79
 
72
- * `#relative` - Answers the relative path from which the object was constructed.
73
- * `#namespace` - Answers the relative namespace as a pathname object from which the object was
80
+ Each of the above objects share the same Object API:
81
+
82
+ * `#relative`: Answers the relative path from which the object was constructed.
83
+ * `#namespace`: Answers the relative namespace as a pathname object from which the object was
74
84
  constructed. The namespace must be identical across the cache, config, and data objects as this is
75
85
  what uniquely identifies and organizes all files associated with your program.
76
- * `#file_name` - Answers the file name from which the object was constructed.
77
- * `#current` - Answers first _existing_ file system path computed by `$XDG_*_HOME` followed by each
78
- computed `$XDG_*_DIRS` path in order defined. Otherwise, `nil` is answered back.
79
- * `#all` - Answers all file system paths which is the combined `$XDG_*_HOME` and
86
+ * `#file_name`: Answers the file name from which the object was constructed.
87
+ * `#active`: Answers first _existing_ file path as computed by `+$XDG_*_HOME+` followed by each
88
+ computed `+$XDG_*_DIRS+` path in order defined. Otherwise, `nil` is answered back.
89
+ * `#global`: Answers the first _existing_ or _non-existing_ global file path only.
90
+ * `#local`: Answers the first _existing_ or _non-existing_ local file path only.
91
+ * `#all`: Answers all file system paths which is the combined `$XDG_*_HOME` and
80
92
  `$XDG_*_DIRS` values in order defined. These paths _may_ or _may not_ exist on the file system.
81
- * `#inspect` - Answers a string representation of default XDG home and directory paths for debugging
93
+ * `#inspect`: Answers a string representation of default XDG home and directory paths for debugging
82
94
  purposes.
83
95
 
84
- Using the `cache` object (created above) as an example, here is what each method answers back:
96
+ Using a `cache` object, for example, here is what each method answers back:
85
97
 
86
98
  [source,ruby]
87
99
  ----
88
- cache.relative # => #<Pathname:example/data.json>
89
- cache.namespace # #<Pathname:example>
90
- cache.file_name # #<Pathname:data.json>
91
- cache.current # #<Pathname:/Users/bkuhlmann/.cache/example/data.json>
92
- cache.all # [#<Pathname:/Users/bkuhlmann/.cache/example/data.json>]
93
- cache.inspect # "XDG_CACHE_HOME=/Users/bkuhlmann/.cache"
100
+ cache = Runcom::Cache.new "demo/content.json"
101
+
102
+ cache.relative # => #<Pathname:demo/content.json>
103
+ cache.namespace # #<Pathname:demo>
104
+ cache.file_name # #<Pathname:content.json>
105
+ cache.active # nil
106
+ cache.global # #<Pathname:/Users/demo/.cache/demo/content.json>
107
+ cache.local # #<Pathname:/Users/demo/Engineering/OSS/runcom/.cache/demo/content.json>
108
+ cache.all # [#<Pathname:/Users/demo/Engineering/OSS/runcom/.cache/demo/content.json>, #<Pathname:/Users/demo/.cache/demo/content.json>]
109
+ cache.inspect # "XDG_CACHE_HOME=/Users/demo/Engineering/OSS/runcom/.cache:/Users/demo/.cache"
94
110
  ----
95
111
 
96
112
  === Variable Priority
@@ -104,76 +120,30 @@ Path precedence is determined in the following order (with the first taking high
104
120
  . *Global Configuration* - When a local configuration isn’t found, the global configuration is used
105
121
  as defined by the _XDG Base Directory Specification_.
106
122
 
107
- === Configuration Specialization
108
-
109
- The `Runcom::Config` deserves additional highlighting as it provides support for loading custom
110
- CLI configurations directly from the command line or from custom locations. It is meant to be used
111
- within your program(s).
112
-
113
- An object is initialized as follows:
114
-
115
- [source,ruby]
116
- ----
117
- configuration = Runcom::Config.new "example/configuration.yml"
118
- ----
119
-
120
- Default settings can be initialized as well:
121
-
122
- [source,ruby]
123
- ----
124
- configuration = Runcom::Config.new "example/configuration.yml", defaults: {name: "Example"}
125
- ----
126
-
127
- Once a configuration has been initialized, a hash representation can be obtained:
128
-
129
- [source,ruby]
130
- ----
131
- configuration.to_h
132
- ----
133
-
134
- A configuration can be merged with another hash (handy for runtime overrides):
135
-
136
- [source,ruby]
137
- ----
138
- updated_configuration = configuration.merge {name: "Updated Name"}
139
- ----
140
-
141
- A configuration can also be merged with another configuration:
142
-
143
- [source,ruby]
144
- ----
145
- updated_configuration = configuration.merge Runcom::Config.new("other", defaults: {a: 1})
146
- ----
147
-
148
- The current path of the configuration can be asked for as well:
149
-
150
- [source,ruby]
151
- ----
152
- configuration.current # "~/.config/example/configuration.yml"
153
- ----
123
+ === Building Blocks
154
124
 
155
- For further details, study the public interface as provided by the
156
- link:lib/runcom/config.rb[`Runcom::Config`] object.
125
+ While {xdg_link} and Runcom are powerful in their own right, a great building block you can add on top of this gem is the {etcher_link} gem which loads, transforms, validates, and produces structured data from raw Runcom information. For more sophisticated applications, this synergetic coupling of `XDG -> Runcom -> Etcher` makes for nicely designed architectures.
157
126
 
158
127
  === Examples
159
128
 
160
129
  Examples of gems built atop this gem are:
161
130
 
162
- * link:https://alchemists.io/projects/rubysmith[Rubysmith] - A command line interface for
131
+ * link:https://alchemists.io/projects/rubysmith[Rubysmith]: A command line interface for
163
132
  smithing Ruby projects.
164
- * link:https://alchemists.io/projects/gemsmith[Gemsmith] - A command line interface for smithing
133
+ * link:https://alchemists.io/projects/gemsmith[Gemsmith]: A command line interface for smithing
165
134
  new Ruby gems.
166
- * link:https://alchemists.io/projects/git-lint[Git Lint] - Enforces consistent Git commits.
167
- * link:https://alchemists.io/projects/milestoner[Milestoner] - A command line interface for
135
+ * link:https://alchemists.io/projects/hanamismith[Hanamismith]: A command line interace for smithing link:https://hanamirb.org[Hanami] projects.
136
+ * link:https://alchemists.io/projects/git-lint[Git Lint]: Enforces consistent Git commits.
137
+ * link:https://alchemists.io/projects/milestoner[Milestoner]: A command line interface for
168
138
  releasing Git repository milestones.
169
- * link:https://alchemists.io/projects/pennyworth[Pennyworth] - A command line interface that
139
+ * link:https://alchemists.io/projects/pennyworth[Pennyworth]: A command line interface that
170
140
  enhances and extends link:https://www.alfredapp.com[Alfred] with Ruby support.
171
- * link:https://alchemists.io/projects/pragmater[Pragmater] - A command line interface for
141
+ * link:https://alchemists.io/projects/pragmater[Pragmater]: A command line interface for
172
142
  managing/formatting source file pragma comments.
173
- * link:https://alchemists.io/projects/sublime_text_kit[Sublime Text Kit] - A command line
143
+ * link:https://alchemists.io/projects/sublime_text_kit[Sublime Text Kit]: A command line
174
144
  interface for managing Sublime Text metadata.
175
- * link:https://alchemists.io/projects/tocer[Tocer] - A command line interface for generating
176
- table of contents for Markdown files.
145
+ * link:https://alchemists.io/projects/tocer[Tocer]: A command line interface for generating
146
+ Markdown table of contents.
177
147
 
178
148
  == Development
179
149
 
data/lib/runcom/cache.rb CHANGED
@@ -7,11 +7,11 @@ module Runcom
7
7
  class Cache
8
8
  extend Forwardable
9
9
 
10
- DEFAULT_CONTEXT = Context.new xdg: XDG::Cache
10
+ CONTEXT = Context.new xdg: XDG::Cache
11
11
 
12
- delegate %i[relative namespace file_name current all inspect] => :common
12
+ delegate %i[relative namespace file_name active global local all inspect] => :common
13
13
 
14
- def initialize path, context: DEFAULT_CONTEXT
14
+ def initialize path, context: CONTEXT
15
15
  @common = Paths::Common.new path, context:
16
16
  end
17
17
 
data/lib/runcom/config.rb CHANGED
@@ -1,53 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "refinements/hashes"
4
- require "yaml"
3
+ require "forwardable"
5
4
 
6
5
  module Runcom
7
6
  # A developer friendly wrapper of XDG config.
8
7
  class Config
9
8
  extend Forwardable
10
- using Refinements::Hashes
11
9
 
12
- DEFAULT_CONTEXT = Context.new xdg: XDG::Config
10
+ CONTEXT = Context.new xdg: XDG::Config
13
11
 
14
- delegate %i[relative namespace file_name current all inspect] => :common
12
+ delegate %i[relative namespace file_name active global local all inspect] => :common
15
13
 
16
- def initialize path, defaults: {}, context: DEFAULT_CONTEXT
17
- @common = Paths::Common.new path, context: @context = context
18
- @settings = defaults.deep_merge process_settings
19
- freeze
14
+ def initialize path, context: CONTEXT
15
+ @common = Paths::Common.new path, context:
20
16
  end
21
17
 
22
- def merge other
23
- self.class.new common.relative, defaults: settings.deep_merge(other.to_h), context:
24
- end
25
-
26
- # :reek:FeatureEnvy
27
- def ==(other) = other.is_a?(Config) && (hash == other.hash)
28
-
29
- alias eql? ==
30
-
31
- def hash = [common.relative, to_h, self.class].hash
32
-
33
- def to_h = settings
34
-
35
18
  private
36
19
 
37
- attr_reader :common, :context, :settings
38
-
39
- def process_settings
40
- load_settings
41
- rescue Psych::SyntaxError
42
- raise Error, "Invalid configuration: #{common.current}."
43
- rescue StandardError
44
- context.defaults
45
- {}
46
- end
47
-
48
- def load_settings
49
- yaml = YAML.load_file common.current
50
- yaml.is_a?(Hash) ? yaml : {}
51
- end
20
+ attr_reader :common
52
21
  end
53
22
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Runcom
4
4
  # A common context for all XDG custom objects.
5
- Context = Struct.new :defaults, :home, :environment, :xdg, keyword_init: true do
6
- def initialize *arguments
5
+ Context = Struct.new :home, :environment, :xdg do
6
+ def initialize(**)
7
7
  super
8
8
 
9
9
  self[:home] ||= Paths::Home
data/lib/runcom/data.rb CHANGED
@@ -7,11 +7,11 @@ module Runcom
7
7
  class Data
8
8
  extend Forwardable
9
9
 
10
- DEFAULT_CONTEXT = Context.new xdg: XDG::Data
10
+ CONTEXT = Context.new xdg: XDG::Data
11
11
 
12
- delegate %i[relative namespace file_name current all inspect] => :common
12
+ delegate %i[relative namespace file_name active global local all inspect] => :common
13
13
 
14
- def initialize path, context: DEFAULT_CONTEXT
14
+ def initialize path, context: CONTEXT
15
15
  @common = Paths::Common.new path, context:
16
16
  end
17
17
 
@@ -24,7 +24,14 @@ module Runcom
24
24
 
25
25
  def file_name = relative.basename
26
26
 
27
- def current = all.select(&:file?).find(&:exist?)
27
+ def active = all.select(&:file?).find(&:exist?)
28
+
29
+ def global
30
+ all.tap { |paths| paths.delete local }
31
+ .first
32
+ end
33
+
34
+ def local = all.first
28
35
 
29
36
  def all = xdg.all.map { |root| root.join relative }
30
37
 
data/lib/runcom/state.rb CHANGED
@@ -7,11 +7,11 @@ module Runcom
7
7
  class State
8
8
  extend Forwardable
9
9
 
10
- DEFAULT_CONTEXT = Context.new xdg: XDG::State
10
+ CONTEXT = Context.new xdg: XDG::State
11
11
 
12
- delegate %i[relative namespace file_name current all inspect] => :common
12
+ delegate %i[relative namespace file_name active global local all inspect] => :common
13
13
 
14
- def initialize path, context: DEFAULT_CONTEXT
14
+ def initialize path, context: CONTEXT
15
15
  @common = Paths::Common.new path, context:
16
16
  end
17
17
 
data/runcom.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "runcom"
5
- spec.version = "9.0.2"
5
+ spec.version = "10.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/runcom"
9
- spec.summary = "An XDG enhanced run command manager for command line interfaces."
9
+ spec.summary = "A XDG enhanced run command manager for command line interfaces."
10
10
  spec.license = "Hippocratic-2.1"
11
11
 
12
12
  spec.metadata = {
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
25
  spec.required_ruby_version = "~> 3.2"
26
- spec.add_dependency "refinements", "~> 10.0"
27
- spec.add_dependency "xdg", "~> 7.0"
26
+ spec.add_dependency "refinements", "~> 11.0"
27
+ spec.add_dependency "xdg", "~> 7.1"
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: 9.0.2
4
+ version: 10.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-03-22 00:00:00.000000000 Z
38
+ date: 2023-06-13 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: '10.0'
46
+ version: '11.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: '10.0'
53
+ version: '11.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.0'
60
+ version: '7.1'
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.0'
67
+ version: '7.1'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: zeitwerk
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -126,8 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.4.9
129
+ rubygems_version: 3.4.14
130
130
  signing_key:
131
131
  specification_version: 4
132
- summary: An XDG enhanced run command manager for command line interfaces.
132
+ summary: A XDG enhanced run command manager for command line interfaces.
133
133
  test_files: []
metadata.gz.sig CHANGED
Binary file