user_space 3.0.3 → 4.0.210114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +44 -24
- data/lib/user_space.rb +21 -27
- metadata +13 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2c25f25272f9f0af6d080d708bc07b09b580c273943d654ff51562c54e78073
|
4
|
+
data.tar.gz: 6d33316656f0d3536fb76bde0d0c1f2980c1c6f122ad084ab254b081a64964d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3db74fdfba700b3bab9139a7b728dc20edf901d47ee5498cc4a7d546eaa21f31f197ff1b82ec487b584118e4746952ffea0160e770e962ae14093bc8e68ccc1
|
7
|
+
data.tar.gz: 76728fce0b2081d921ba4258607464f228f2279a055e9c1b13db4665ce4eabea35cfccb58251461ab90d0fa49059a53ea021fd92aa377346dba2d4cec6ff93db
|
data/README.md
CHANGED
@@ -1,45 +1,65 @@
|
|
1
1
|
# UserSpace
|
2
2
|
|
3
|
-
* [VERSION
|
3
|
+
* [VERSION 4.0.210114](https://github.com/carlosjhr64/user_space/releases)
|
4
4
|
* [github](https://www.github.com/carlosjhr64/user_space)
|
5
5
|
* [rubygems](https://rubygems.org/gems/user_space)
|
6
6
|
|
7
7
|
## DESCRIPTION:
|
8
8
|
|
9
|
-
Maintains the
|
9
|
+
Maintains the user's cache, config, and data directories
|
10
|
+
with the gem-apps cache, config, and data files.
|
10
11
|
|
11
12
|
## SYNOPSIS:
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
14
|
+
```ruby
|
15
|
+
require 'json' # Using JSON parser for the config file.
|
16
|
+
require 'user_space'
|
17
|
+
|
18
|
+
module App
|
19
|
+
# ::App::CONFIG is your app's configuration.
|
20
|
+
CONFIG = {:tts=>'espeak', }
|
21
|
+
VERSION = '1.2.3'
|
22
|
+
end
|
23
|
+
|
24
|
+
USERSPACE = UserSpace.new(parser:JSON, appname:'myapp') #~> ^#<UserSpace:
|
25
|
+
# Will maintain these directories:
|
26
|
+
['~/.cache/myapp',
|
27
|
+
'~/.config/myapp',
|
28
|
+
'~/.local/share/myapp'
|
29
|
+
].all?{File.directory? File.expand_path _1} #=> true
|
30
|
+
|
31
|
+
# Unless this version has been installed,
|
32
|
+
# we copy over our data and cache directories.
|
33
|
+
USERSPACE.install unless USERSPACE.version == App::VERSION
|
34
|
+
# We have a version file:
|
35
|
+
File.exist? File.expand_path '~/.local/share/myapp/VERSION' #=> true
|
36
|
+
|
37
|
+
if USERSPACE.config?
|
38
|
+
# Because JSON hashes by String, converting to Symbol.
|
39
|
+
# We pad up App::CONFIG with user's preferences:
|
40
|
+
USERSPACE.config.each{|opt, value| App::CONFIG[opt.to_sym] = value}
|
41
|
+
else
|
42
|
+
# We initialize user preferences with our initial App::CONFIG
|
43
|
+
STDERR.puts "Writting '#{USERSPACE.config_file_name}'"
|
44
|
+
USERSPACE.config = App::CONFIG
|
45
|
+
end
|
46
|
+
# To do the same thing, you can also say:
|
47
|
+
# USERSPACE.configures(App::CONFIG)
|
48
|
+
# We have a config file:
|
49
|
+
File.exist? File.expand_path '~/.config/myapp/config.json' #=> true
|
50
|
+
```
|
33
51
|
|
34
52
|
## INSTALL:
|
35
53
|
|
36
|
-
|
54
|
+
```shell
|
55
|
+
$ gem install user_space
|
56
|
+
```
|
37
57
|
|
38
58
|
## LICENSE:
|
39
59
|
|
40
60
|
(The MIT License)
|
41
61
|
|
42
|
-
Copyright (c)
|
62
|
+
Copyright (c) 2021 CarlosJHR64
|
43
63
|
|
44
64
|
Permission is hereby granted, free of charge, to any person obtaining
|
45
65
|
a copy of this software and associated documentation files (the
|
data/lib/user_space.rb
CHANGED
@@ -1,36 +1,30 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'xdg'
|
3
2
|
# Requires:
|
4
3
|
#`ruby`
|
5
4
|
|
6
5
|
class UserSpace
|
7
|
-
VERSION = '
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
6
|
+
VERSION = '4.0.210114'
|
7
|
+
XDG = {
|
8
|
+
'cache' => ENV['XDG_CACHE_HOME'] || File.expand_path('~/.cache'),
|
9
|
+
'config' => ENV['XDG_CONFIG_HOME'] || File.expand_path('~/.config'),
|
10
|
+
'data' => ENV['XDG_DATA_HOME'] || File.expand_path('~/.local/share'),
|
11
|
+
}
|
14
12
|
|
15
13
|
attr_reader :parser,:ext,:appname,:xdgbases,:appdir,:config
|
16
|
-
def initialize(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
config: 'config'
|
23
|
-
)
|
14
|
+
def initialize( parser:,
|
15
|
+
ext: parser.to_s.downcase,
|
16
|
+
appname: File.basename($0),
|
17
|
+
xdgbases: ['cache', 'config', 'data'],
|
18
|
+
appdir: File.dirname(__dir__),
|
19
|
+
config: 'config')
|
24
20
|
@parser,@ext,@appname,@xdgbases,@appdir,@config = parser,ext,appname,xdgbases,appdir,config
|
25
21
|
install(false) # install with no overwrite
|
26
22
|
end
|
27
23
|
|
28
24
|
def xdg_pairs
|
29
25
|
@xdgbases.each do |base|
|
30
|
-
|
31
|
-
|
32
|
-
basedir = File.join @appdir, base.downcase
|
33
|
-
yield basedir, userdir
|
26
|
+
# yield basedir, userdir
|
27
|
+
yield File.join(@appdir, base), File.join(XDG[base], @appname)
|
34
28
|
end
|
35
29
|
end
|
36
30
|
|
@@ -64,25 +58,25 @@ class UserSpace
|
|
64
58
|
end
|
65
59
|
|
66
60
|
def cachedir
|
67
|
-
File.join XDG['
|
61
|
+
File.join XDG['cache'], @appname
|
68
62
|
end
|
69
63
|
|
70
64
|
def configdir
|
71
|
-
File.join XDG['
|
65
|
+
File.join XDG['config'], @appname
|
72
66
|
end
|
73
67
|
|
74
68
|
def datadir
|
75
|
-
File.join XDG['
|
69
|
+
File.join XDG['data'], @appname
|
76
70
|
end
|
77
71
|
|
78
72
|
# Not really for public use.
|
79
73
|
def config_file_name
|
80
|
-
File.join XDG['
|
74
|
+
File.join XDG['config'], @appname, "#{@config}.#{@ext}"
|
81
75
|
end
|
82
76
|
|
83
77
|
# Not really for public use.
|
84
78
|
def version_file_name
|
85
|
-
File.join XDG['
|
79
|
+
File.join XDG['data'], @appname, 'VERSION'
|
86
80
|
end
|
87
81
|
|
88
82
|
def config?
|
@@ -105,8 +99,8 @@ class UserSpace
|
|
105
99
|
end
|
106
100
|
|
107
101
|
def configures(hash)
|
108
|
-
if
|
109
|
-
|
102
|
+
if config? # file exists
|
103
|
+
config.each{|opt, value| hash[opt.to_sym] = value}
|
110
104
|
else
|
111
105
|
$stderr.puts config_file_name if $VERBOSE
|
112
106
|
self.config = hash
|
metadata
CHANGED
@@ -1,32 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_space
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.210114
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carlosjhr64
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.2.3
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 2.2.3
|
27
|
-
description: 'Maintains the app''s XDG features: app''s cache, config, and data directories.
|
28
|
-
|
29
|
-
'
|
11
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
Maintains the user's cache, config, and data directories
|
15
|
+
with the gem-apps cache, config, and data files.
|
30
16
|
email: carlosjhr64@gmail.com
|
31
17
|
executables: []
|
32
18
|
extensions: []
|
@@ -38,7 +24,7 @@ homepage: https://github.com/carlosjhr64/user_space
|
|
38
24
|
licenses:
|
39
25
|
- MIT
|
40
26
|
metadata: {}
|
41
|
-
post_install_message:
|
27
|
+
post_install_message:
|
42
28
|
rdoc_options: []
|
43
29
|
require_paths:
|
44
30
|
- lib
|
@@ -53,9 +39,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
requirements:
|
56
|
-
- 'ruby: ruby
|
57
|
-
rubygems_version: 3.
|
58
|
-
signing_key:
|
42
|
+
- 'ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]'
|
43
|
+
rubygems_version: 3.2.3
|
44
|
+
signing_key:
|
59
45
|
specification_version: 4
|
60
|
-
summary:
|
46
|
+
summary: Maintains the user's cache, config, and data directories with the gem-apps
|
47
|
+
cache, config, and data files.
|
61
48
|
test_files: []
|