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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf4e3a9583ae082cb4669e116317b6445d6d716bc87fee323e5a3edc3d9ff0c1
4
- data.tar.gz: 15412eab2d3cffde140b178cf30daaf78db3abcb934d1fd82ae884d64e5c51b4
3
+ metadata.gz: 323797e110d0fba7f1e71c2d372a6c0e76faa36f285a994fc88b197bbe30f200
4
+ data.tar.gz: 50c924347d52fee0cd56c5c7ee74d533bed66a8b21f58e846dfcd6ec3a07f178
5
5
  SHA512:
6
- metadata.gz: ba341827e250f0ce016a096a97fd84ad7b6fe1a3213448501f57f1dd153b9ba4ae6829c6823d3826638c437ac30493cec2ff61ebbb62d288cffbb77b2661427b
7
- data.tar.gz: 69aed37da57f947abd3d578c73d2f90f20c41b315305cc7192a839e36f30ee4a544cce911beb1d01e786899dddf0891b9e522c5a2a1b9875a71430a9325dcfa3
6
+ metadata.gz: 7a4b611fc28735bc5abff558cde0d78165746e298038c05d5a5df6ee882a9d7c4c14428bd5d058a0dca4b719f2a5d5c34edaa2000dcf11bfc467d9e4a07cdd84
7
+ data.tar.gz: 7a47317e926d088b29f214c43dafca23b24ad9bdd5f7d5cc51ed744c228e4037aef18e13055bab52b3d26dc85251bec79b5efe96d8502033d70e44bb1caaeba9
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.3](https://www.ruby-lang.org)
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
@@ -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),
@@ -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),
@@ -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),
@@ -28,6 +28,10 @@ module XDG
28
28
  data.directories
29
29
  end
30
30
 
31
+ def inspect
32
+ "#{cache.inspect} #{config.inspect} #{data.inspect}"
33
+ end
34
+
31
35
  private
32
36
 
33
37
  attr_reader :cache, :config, :data
@@ -12,7 +12,7 @@ module XDG
12
12
  end
13
13
 
14
14
  def self.version
15
- "3.0.2"
15
+ "3.1.0"
16
16
  end
17
17
 
18
18
  def self.version_label
@@ -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
@@ -23,6 +23,10 @@ module XDG
23
23
  directories.prepend home
24
24
  end
25
25
 
26
+ def inspect
27
+ [initial_home.inspect, initial_directories.inspect].reject(&:empty?).join " "
28
+ end
29
+
26
30
  private
27
31
 
28
32
  attr_reader :initial_home, :initial_directories
@@ -18,13 +18,24 @@ module XDG
18
18
  end
19
19
 
20
20
  def dynamic
21
- environment.fetch(pair.key, paths).split(DELIMITER).uniq.map(&method(:expand))
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
@@ -19,23 +19,27 @@ module XDG
19
19
  end
20
20
 
21
21
  def default
22
- expand_home_for String(value)
22
+ expand String(value)
23
23
  end
24
24
 
25
25
  def dynamic
26
- String(environment[key]).then { |path| path.empty? ? default : expand_home_for(path) }
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 home
34
- Pathname environment.fetch(HOME_KEY)
37
+ def expand path
38
+ home.join(path).expand_path
35
39
  end
36
40
 
37
- def expand_home_for path
38
- home.join(path).expand_path
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.2
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-09-01 00:00:00.000000000 Z
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