user_space 3.0.3 → 4.0.210114

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -24
  3. data/lib/user_space.rb +21 -27
  4. metadata +13 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dfcc971479291e90e318bd01ba58aa13ebfd8879b8cea95e308b37530933393
4
- data.tar.gz: c0bccd867a3a6aa2ab2a6af9280391e6e6c0393b1f9df9664dd9f0ac7f0ccdc0
3
+ metadata.gz: e2c25f25272f9f0af6d080d708bc07b09b580c273943d654ff51562c54e78073
4
+ data.tar.gz: 6d33316656f0d3536fb76bde0d0c1f2980c1c6f122ad084ab254b081a64964d4
5
5
  SHA512:
6
- metadata.gz: a22b5d23502cb1216d444510f1fe0474125a9d5b9ce3bfd87908516071f1efc59290ce367eda718bfb259bc5f1306796cb4e41f075f7b9b6b7623eee7a457fab
7
- data.tar.gz: 210fad38ba6a7c41852176660b59ee0301eec0ad193cf04b9cc7273c8de0601942a6b2a9415990379ed59515e933c4cc576c4072a7a9aa52f28e290fa0180403
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.0.3](https://github.com/carlosjhr64/user_space/releases)
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 app's XDG features: app's cache, config, and data directories.
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
- require 'json' # Using JSON parser for the config file.
14
- require 'user_space'
15
- # APP::CONFIG is your app's configuration.
16
- # Perhaps like...
17
- APP::CONFIG = {:tts=>'espeak', }
18
- USERSPACE = UserSpace.new(JSON)
19
- # Unless this version has been installed,
20
- # we copy over our data and cache directories.
21
- USERSPACE.install unless USERSPACE.version == APP::VERSION
22
- if USERSPACE.config?
23
- # Because JSON hashes by String, converting to Symbol.
24
- # We pad up APP::CONFIG with user's preferences:
25
- USERSPACE.config.each{|opt, value| APP::CONFIG[opt.to_sym] = value}
26
- else
27
- # We initialize user preferences with our initial APP::CONFIG
28
- STDERR.puts "Writting '#{USERSPACE.config_file_name}'"
29
- USERSPACE.config = APP::CONFIG
30
- end
31
- # To do the same thing, you can also say:
32
- # USERSPACE.configures(APP::CONFIG)
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
- sudo gem install user_space
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) 2020 CarlosJHR64
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
@@ -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 = '3.0.3'
8
-
9
- def self.appdir
10
- appdir = File.dirname File.dirname caller_locations(1,1)[0].path
11
- appdir = File.dirname appdir if File.basename(appdir)=='lib'
12
- File.expand_path appdir
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
- parser,
18
- ext: parser.to_s.downcase,
19
- appname: File.basename($0),
20
- xdgbases: ['CACHE', 'CONFIG', 'DATA'],
21
- appdir: UserSpace.appdir,
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
- xdg = XDG[base].to_s
31
- userdir = File.join(xdg, @appname)
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['CACHE'].to_s, @appname
61
+ File.join XDG['cache'], @appname
68
62
  end
69
63
 
70
64
  def configdir
71
- File.join XDG['CONFIG'].to_s, @appname
65
+ File.join XDG['config'], @appname
72
66
  end
73
67
 
74
68
  def datadir
75
- File.join XDG['DATA'].to_s, @appname
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['CONFIG'].to_s, @appname, "#{@config}.#{@ext}"
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['DATA'].to_s, @appname, 'VERSION'
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 self.config? # file exists
109
- self.config.each{|opt, value| hash[opt.to_sym] = value}
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: 3.0.3
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: 2020-08-27 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: xdg
15
- requirement: !ruby/object:Gem::Requirement
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 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]'
57
- rubygems_version: 3.1.2
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: 'Maintains the app''s XDG features: app''s cache, config, and data directories.'
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: []