xdg 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +43 -1
- data/lib/xdg/cache.rb +1 -1
- data/lib/xdg/config.rb +1 -1
- data/lib/xdg/data.rb +1 -1
- data/lib/xdg/environment.rb +4 -0
- data/lib/xdg/identity.rb +1 -1
- data/lib/xdg/pair.rb +20 -0
- data/lib/xdg/paths/combined.rb +4 -0
- data/lib/xdg/paths/directory.rb +12 -1
- data/lib/xdg/paths/standard.rb +10 -6
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 323797e110d0fba7f1e71c2d372a6c0e76faa36f285a994fc88b197bbe30f200
|
4
|
+
data.tar.gz: 50c924347d52fee0cd56c5c7ee74d533bed66a8b21f58e846dfcd6ec3a07f178
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4b611fc28735bc5abff558cde0d78165746e298038c05d5a5df6ee882a9d7c4c14428bd5d058a0dca4b719f2a5d5c34edaa2000dcf11bfc467d9e4a07cdd84
|
7
|
+
data.tar.gz: 7a47317e926d088b29f214c43dafca23b24ad9bdd5f7d5cc51ed744c228e4037aef18e13055bab52b3d26dc85251bec79b5efe96d8502033d70e44bb1caaeba9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ sugar that includes what is found in this gem, make sure to check out the
|
|
25
25
|
- [Setup](#setup)
|
26
26
|
- [Usage](#usage)
|
27
27
|
- [Overview](#overview)
|
28
|
+
- [Examples](#examples)
|
28
29
|
- [Variable Defaults](#variable-defaults)
|
29
30
|
- [Variable Behavior](#variable-behavior)
|
30
31
|
- [`$XDG_*_DIRS`](#xdg__dirs)
|
@@ -52,7 +53,7 @@ sugar that includes what is found in this gem, make sure to check out the
|
|
52
53
|
|
53
54
|
## Requirements
|
54
55
|
|
55
|
-
1. [Ruby 2.6.
|
56
|
+
1. [Ruby 2.6.4](https://www.ruby-lang.org)
|
56
57
|
|
57
58
|
## Setup
|
58
59
|
|
@@ -98,6 +99,47 @@ following messages:
|
|
98
99
|
- `#all` - Answers an array of *all* directories as computed from the combined `$XDG_*_HOME` and
|
99
100
|
`$XDG_*_DIRS` values (with `$XDG_*_HOME` prefixed at the start of the array).
|
100
101
|
|
102
|
+
#### Examples
|
103
|
+
|
104
|
+
The following are examples of what you would see when playing around with the XDG objects within an
|
105
|
+
IRB console (taken from my own environment):
|
106
|
+
|
107
|
+
require "xdg"
|
108
|
+
|
109
|
+
# Initialization
|
110
|
+
environment = XDG::Environment.new
|
111
|
+
cache = XDG::Cache.new
|
112
|
+
config = XDG::Config.new
|
113
|
+
data = XDG::Data.new
|
114
|
+
|
115
|
+
# Inspection
|
116
|
+
environment.inspect # => XDG_CACHE_HOME=/Users/bkuhlmann/.cache XDG_CONFIG_HOME=/Users/bkuhlmann/.config XDG_CONFIG_DIRS=/etc/xdg XDG_DATA_HOME=/Users/bkuhlmann/.local/share XDG_DATA_DIRS=/usr/local/share:/usr/share
|
117
|
+
cache.inspect # => "XDG_CACHE_HOME=/Users/bkuhlmann/.cache"
|
118
|
+
config.inspect # => "XDG_CONFIG_HOME=/Users/bkuhlmann/.config XDG_CONFIG_DIRS=/etc/xdg"
|
119
|
+
data.inspect # => "XDG_DATA_HOME=/Users/bkuhlmann/.local/share XDG_DATA_DIRS=/usr/local/share:/usr/share"
|
120
|
+
|
121
|
+
# Paths
|
122
|
+
environment.cache_home # => #<Pathname:/Users/bkuhlmann/.cache>
|
123
|
+
environment.config_home # => #<Pathname:/Users/bkuhlmann/.config>
|
124
|
+
environment.config_dirs # => [#<Pathname:/etc/xdg>]
|
125
|
+
environment.data_home # => #<Pathname:/Users/bkuhlmann/.local/share>
|
126
|
+
environment.data_dirs # => [#<Pathname:/usr/local/share>, #<Pathname:/usr/share>]
|
127
|
+
|
128
|
+
cache.home # => #<Pathname:/Users/bkuhlmann/.cache>
|
129
|
+
cache.directories # => []
|
130
|
+
cache.all # => [#<Pathname:/Users/bkuhlmann/.cache>]
|
131
|
+
|
132
|
+
config.home # => #<Pathname:/Users/bkuhlmann/.config>
|
133
|
+
config.directories # => [#<Pathname:/etc/xdg>]
|
134
|
+
config.all # => [#<Pathname:/Users/bkuhlmann/.config>, #<Pathname:/etc/xdg>]
|
135
|
+
|
136
|
+
data.home # => #<Pathname:/Users/bkuhlmann/.local/share>
|
137
|
+
data.directories # => [#<Pathname:/usr/local/share>, #<Pathname:/usr/share>]
|
138
|
+
data.all # => [#<Pathname:/Users/bkuhlmann/.local/share>, #<Pathname:/usr/local/share>, #<Pathname:/usr/share>]
|
139
|
+
|
140
|
+
As you can see from above, each XDG object answers back a `Pathname` which means you have the
|
141
|
+
full `Pathname` API at your fingertips to build upon the output of these objects as needed.
|
142
|
+
|
101
143
|
#### Variable Defaults
|
102
144
|
|
103
145
|
The *XDG Base Directory Specification* defines environment variables and associated default values
|
data/lib/xdg/cache.rb
CHANGED
@@ -8,7 +8,7 @@ module XDG
|
|
8
8
|
|
9
9
|
HOME_PAIR = Pair["XDG_CACHE_HOME", ".cache"].freeze
|
10
10
|
|
11
|
-
delegate %i[home directories all] => :combined
|
11
|
+
delegate %i[home directories all inspect] => :combined
|
12
12
|
|
13
13
|
def initialize home: Paths::Standard, directories: Paths::Directory, environment: ENV
|
14
14
|
@combined = Paths::Combined.new home.new(HOME_PAIR, environment),
|
data/lib/xdg/config.rb
CHANGED
@@ -9,7 +9,7 @@ module XDG
|
|
9
9
|
HOME_PAIR = Pair["XDG_CONFIG_HOME", ".config"].freeze
|
10
10
|
DIRS_PAIR = Pair["XDG_CONFIG_DIRS", "/etc/xdg"].freeze
|
11
11
|
|
12
|
-
delegate %i[home directories all] => :combined
|
12
|
+
delegate %i[home directories all inspect] => :combined
|
13
13
|
|
14
14
|
def initialize home: Paths::Standard, directories: Paths::Directory, environment: ENV
|
15
15
|
@combined = Paths::Combined.new home.new(HOME_PAIR, environment),
|
data/lib/xdg/data.rb
CHANGED
@@ -9,7 +9,7 @@ module XDG
|
|
9
9
|
HOME_PAIR = Pair["XDG_DATA_HOME", ".local/share"].freeze
|
10
10
|
DIRS_PAIR = Pair["XDG_DATA_DIRS", "/usr/local/share:/usr/share"].freeze
|
11
11
|
|
12
|
-
delegate %i[home directories all] => :combined
|
12
|
+
delegate %i[home directories all inspect] => :combined
|
13
13
|
|
14
14
|
def initialize home: Paths::Standard, directories: Paths::Directory, environment: ENV
|
15
15
|
@combined = Paths::Combined.new home.new(HOME_PAIR, environment),
|
data/lib/xdg/environment.rb
CHANGED
data/lib/xdg/identity.rb
CHANGED
data/lib/xdg/pair.rb
CHANGED
@@ -1,10 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module XDG
|
4
|
+
PAIR_DELIMITER = "="
|
5
|
+
|
4
6
|
# A generic key-value pair (KVP).
|
5
7
|
Pair = Struct.new :key, :value do
|
6
8
|
def to_env
|
7
9
|
Hash[*values]
|
8
10
|
end
|
11
|
+
|
12
|
+
def key?
|
13
|
+
key.to_s.size.positive?
|
14
|
+
end
|
15
|
+
|
16
|
+
def value?
|
17
|
+
value.to_s.size.positive?
|
18
|
+
end
|
19
|
+
|
20
|
+
def empty?
|
21
|
+
!(key? && value?)
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
return "" unless key? || value?
|
26
|
+
|
27
|
+
"#{key}#{PAIR_DELIMITER}#{value}"
|
28
|
+
end
|
9
29
|
end
|
10
30
|
end
|
data/lib/xdg/paths/combined.rb
CHANGED
data/lib/xdg/paths/directory.rb
CHANGED
@@ -18,13 +18,24 @@ module XDG
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def dynamic
|
21
|
-
environment.
|
21
|
+
String(environment[key]).then { |env_paths| env_paths.empty? ? paths : env_paths }
|
22
|
+
.split(DELIMITER)
|
23
|
+
.uniq
|
24
|
+
.map(&method(:expand))
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
[key, dynamic.join(DELIMITER)].reject(&:empty?).join XDG::PAIR_DELIMITER
|
22
29
|
end
|
23
30
|
|
24
31
|
private
|
25
32
|
|
26
33
|
attr_reader :pair, :environment
|
27
34
|
|
35
|
+
def key
|
36
|
+
String pair.key
|
37
|
+
end
|
38
|
+
|
28
39
|
def paths
|
29
40
|
String pair.value
|
30
41
|
end
|
data/lib/xdg/paths/standard.rb
CHANGED
@@ -19,23 +19,27 @@ module XDG
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def default
|
22
|
-
|
22
|
+
expand String(value)
|
23
23
|
end
|
24
24
|
|
25
25
|
def dynamic
|
26
|
-
String(environment[key]).then { |path| path.empty? ? default :
|
26
|
+
String(environment[key]).then { |path| path.empty? ? default : expand(path) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def inspect
|
30
|
+
[pair.key, dynamic].compact.join XDG::PAIR_DELIMITER
|
27
31
|
end
|
28
32
|
|
29
33
|
private
|
30
34
|
|
31
35
|
attr_reader :pair, :environment
|
32
36
|
|
33
|
-
def
|
34
|
-
|
37
|
+
def expand path
|
38
|
+
home.join(path).expand_path
|
35
39
|
end
|
36
40
|
|
37
|
-
def
|
38
|
-
|
41
|
+
def home
|
42
|
+
Pathname environment.fetch(HOME_KEY)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xdg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -28,7 +28,7 @@ cert_chain:
|
|
28
28
|
dKvURM+1PwDCzC5tvRwjhUJIizau6+MtkFCvJHmaAj1aZL3odcPejHj5Hxt/0CUW
|
29
29
|
y84=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date: 2019-
|
31
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
32
32
|
dependencies:
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler-audit
|
metadata.gz.sig
CHANGED
Binary file
|