user_space 2.0.1 → 4.1.210122
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 +5 -5
- data/README.md +81 -0
- data/lib/user_space.rb +127 -4
- metadata +15 -40
- data/README.rdoc +0 -64
- data/lib/user_space/user_space.rb +0 -144
- data/lib/user_space/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: affe703bd77f1caf7cd1196cf3d24ccc66340bda26163a4d333ac446bc6249a7
|
4
|
+
data.tar.gz: 9e0ab93da71eefc3bbc90630f26788ffc7fa4f65a5f581d7da3799c9da9aac37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef0d5faf595eb3980161f5725bf9bc1092d63bfd1ce1b46fdd3cc1b6283ee5046033cdd7b8ab881edbff0a4c6fafac54bc46593b5c342695bd303d629880608a
|
7
|
+
data.tar.gz: e9a9fe8cd05890af3f8527e24c1314c76be12f830ec33682b25834c561a2d9f79b25f058ebbd7d2502210078c2fe7451f796cb3eb6af4b744070c589d88a9aa3
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# UserSpace
|
2
|
+
|
3
|
+
* [VERSION 4.1.210122](https://github.com/carlosjhr64/user_space/releases)
|
4
|
+
* [github](https://www.github.com/carlosjhr64/user_space)
|
5
|
+
* [rubygems](https://rubygems.org/gems/user_space)
|
6
|
+
|
7
|
+
## DESCRIPTION:
|
8
|
+
|
9
|
+
Maintains the user's cache, config, and data directories
|
10
|
+
with the gem-apps cache, config, and data files.
|
11
|
+
|
12
|
+
## SYNOPSIS:
|
13
|
+
|
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
|
+
```
|
51
|
+
|
52
|
+
## INSTALL:
|
53
|
+
|
54
|
+
```shell
|
55
|
+
$ gem install user_space
|
56
|
+
```
|
57
|
+
|
58
|
+
## LICENSE:
|
59
|
+
|
60
|
+
(The MIT License)
|
61
|
+
|
62
|
+
Copyright (c) 2021 CarlosJHR64
|
63
|
+
|
64
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
65
|
+
a copy of this software and associated documentation files (the
|
66
|
+
'Software'), to deal in the Software without restriction, including
|
67
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
68
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
69
|
+
permit persons to whom the Software is furnished to do so, subject to
|
70
|
+
the following conditions:
|
71
|
+
|
72
|
+
The above copyright notice and this permission notice shall be
|
73
|
+
included in all copies or substantial portions of the Software.
|
74
|
+
|
75
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
76
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
77
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
78
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
79
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
80
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
81
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/user_space.rb
CHANGED
@@ -1,7 +1,130 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'json' # default parser
|
3
|
-
require 'xdg'
|
4
|
-
require 'user_space/version.rb'
|
5
|
-
require 'user_space/user_space.rb'
|
6
2
|
# Requires:
|
7
3
|
#`ruby`
|
4
|
+
|
5
|
+
class UserSpace
|
6
|
+
VERSION = '4.1.210122'
|
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
|
+
}
|
12
|
+
|
13
|
+
def self.appdir
|
14
|
+
File.dirname File.dirname File.expand_path caller(1..2)[1].split(':',2)[0]
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :parser,:ext,:appname,:xdgbases,:appdir,:config
|
18
|
+
def initialize( parser:,
|
19
|
+
appdir: UserSpace.appdir,
|
20
|
+
ext: parser.to_s.downcase,
|
21
|
+
appname: File.basename($0),
|
22
|
+
xdgbases: ['cache', 'config', 'data'],
|
23
|
+
config: 'config')
|
24
|
+
@parser,@ext,@appname,@xdgbases,@appdir,@config = parser,ext,appname,xdgbases,appdir,config
|
25
|
+
install(false) # install with no overwrite
|
26
|
+
end
|
27
|
+
|
28
|
+
def xdg_pairs
|
29
|
+
@xdgbases.each do |base|
|
30
|
+
# yield basedir, userdir
|
31
|
+
yield File.join(@appdir, base), File.join(XDG[base], @appname)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Note that initialize will not overwrite anything.
|
36
|
+
# This overwrites the user's data directory with a fresh install.
|
37
|
+
# App should consider being nice about this,
|
38
|
+
# like warn the user or something.
|
39
|
+
def install(overwrite=true)
|
40
|
+
xdg_pairs do |basedir, userdir|
|
41
|
+
if File.exist?(userdir)
|
42
|
+
# Sanity check
|
43
|
+
raise "Not a directory: #{userdir}" unless File.directory?(userdir)
|
44
|
+
# Pre-existing directory.
|
45
|
+
# Return unless user wants to overwrite.
|
46
|
+
next unless overwrite
|
47
|
+
else
|
48
|
+
Dir.mkdir(userdir, 0700)
|
49
|
+
end
|
50
|
+
if File.directory? basedir
|
51
|
+
Dir.glob("#{basedir}/**/*").each do |src|
|
52
|
+
dest = src.sub(basedir, userdir)
|
53
|
+
if File.directory? src
|
54
|
+
Dir.mkdir dest unless File.exist? dest
|
55
|
+
else
|
56
|
+
FileUtils.cp src, dest
|
57
|
+
end
|
58
|
+
FileUtils.chmod('u+rwX,go-rwx', dest)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def cachedir
|
65
|
+
File.join XDG['cache'], @appname
|
66
|
+
end
|
67
|
+
|
68
|
+
def configdir
|
69
|
+
File.join XDG['config'], @appname
|
70
|
+
end
|
71
|
+
|
72
|
+
def datadir
|
73
|
+
File.join XDG['data'], @appname
|
74
|
+
end
|
75
|
+
|
76
|
+
# Not really for public use.
|
77
|
+
def config_file_name
|
78
|
+
File.join XDG['config'], @appname, "#{@config}.#{@ext}"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Not really for public use.
|
82
|
+
def version_file_name
|
83
|
+
File.join XDG['data'], @appname, 'VERSION'
|
84
|
+
end
|
85
|
+
|
86
|
+
def config?
|
87
|
+
File.exist?(config_file_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Reads config
|
91
|
+
def config
|
92
|
+
@parser.load File.read(config_file_name)
|
93
|
+
rescue
|
94
|
+
$stderr.puts $!.message if $VERBOSE
|
95
|
+
$stderr.puts $!.backtrace if $DEBUG
|
96
|
+
nil
|
97
|
+
end
|
98
|
+
|
99
|
+
# Saves config
|
100
|
+
def config=(obj)
|
101
|
+
dump = (@parser.respond_to?(:pretty_generate))? @parser.pretty_generate(obj) : @parser.dump(obj)
|
102
|
+
File.open(config_file_name, 'w', 0600){|fh|fh.puts dump}
|
103
|
+
end
|
104
|
+
|
105
|
+
def configures(hash)
|
106
|
+
if config? # file exists
|
107
|
+
config.each{|opt, value| hash[opt.to_sym] = value}
|
108
|
+
else
|
109
|
+
$stderr.puts config_file_name if $VERBOSE
|
110
|
+
self.config = hash
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def version?
|
115
|
+
File.exist?(version_file_name)
|
116
|
+
end
|
117
|
+
|
118
|
+
# This reads the data directory's version file
|
119
|
+
def version
|
120
|
+
File.read(version_file_name).strip
|
121
|
+
rescue
|
122
|
+
$stderr.puts $!.message if $VERBOSE
|
123
|
+
$stderr.puts $!.backtrace if $DEBUG
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def version=(v)
|
128
|
+
File.open(version_file_name, 'w', 0600){|fh| fh.puts v}
|
129
|
+
end
|
130
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_space
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.1.210122
|
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
|
-
- !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'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.2.3
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.2'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 2.2.3
|
11
|
+
date: 2021-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
33
13
|
description: |
|
34
|
-
|
14
|
+
Maintains the user's cache, config, and data directories
|
15
|
+
with the gem-apps cache, config, and data files.
|
35
16
|
email: carlosjhr64@gmail.com
|
36
17
|
executables: []
|
37
18
|
extensions: []
|
38
|
-
extra_rdoc_files:
|
39
|
-
- README.rdoc
|
19
|
+
extra_rdoc_files: []
|
40
20
|
files:
|
41
|
-
- README.
|
21
|
+
- README.md
|
42
22
|
- lib/user_space.rb
|
43
|
-
- lib/user_space/user_space.rb
|
44
|
-
- lib/user_space/version.rb
|
45
23
|
homepage: https://github.com/carlosjhr64/user_space
|
46
24
|
licenses:
|
47
25
|
- MIT
|
48
26
|
metadata: {}
|
49
|
-
post_install_message:
|
50
|
-
rdoc_options:
|
51
|
-
- "--main"
|
52
|
-
- README.rdoc
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
53
29
|
require_paths:
|
54
30
|
- lib
|
55
31
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -63,11 +39,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
39
|
- !ruby/object:Gem::Version
|
64
40
|
version: '0'
|
65
41
|
requirements:
|
66
|
-
- 'ruby: ruby
|
67
|
-
|
68
|
-
|
69
|
-
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:
|
70
45
|
specification_version: 4
|
71
|
-
summary:
|
46
|
+
summary: Maintains the user's cache, config, and data directories with the gem-apps
|
47
|
+
cache, config, and data files.
|
72
48
|
test_files: []
|
73
|
-
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
= user_space
|
2
|
-
|
3
|
-
github :: https://www.github.com/carlosjhr64/user_space
|
4
|
-
rubygems :: https://rubygems.org/gems/user_space
|
5
|
-
|
6
|
-
== DESCRIPTION:
|
7
|
-
|
8
|
-
Automates certain XDG features.
|
9
|
-
|
10
|
-
== SYNOPSIS:
|
11
|
-
|
12
|
-
require 'user_space'
|
13
|
-
# APP::CONFIG is your app's configuration.
|
14
|
-
# Perhaps like...
|
15
|
-
APP::CONFIG = {:tts=>'espeak', }
|
16
|
-
# By default, UserSpace works with the JSON parser.
|
17
|
-
USERSPACE = UserSpace.new
|
18
|
-
# Unless this version has been installed,
|
19
|
-
# we copy over our data and cache directories.
|
20
|
-
USERSPACE.install unless USERSPACE.version == APP::VERSION
|
21
|
-
if USERSPACE.config?
|
22
|
-
# Because JSON hashes by String, converting to Symbol.
|
23
|
-
# We pad up APP::CONFIG with user's preferences:
|
24
|
-
USERSPACE.config.each{|opt, value| APP::CONFIG[opt.to_sym] = value}
|
25
|
-
else
|
26
|
-
# We initialize user preferences with our initial APP::CONFIG
|
27
|
-
STDERR.puts "Writting '#{USERSPACE.config_file_name}'"
|
28
|
-
USERSPACE.config = APP::CONFIG
|
29
|
-
end
|
30
|
-
# To do the same thing, you can also say:
|
31
|
-
# USERSPACE.configures(APP::CONFIG)
|
32
|
-
|
33
|
-
== FEATURES:
|
34
|
-
|
35
|
-
* used in mplay[https://www.rubygems.org/gems/mplay]
|
36
|
-
|
37
|
-
== INSTALL:
|
38
|
-
|
39
|
-
sudo gem install user_space
|
40
|
-
|
41
|
-
== LICENSE:
|
42
|
-
|
43
|
-
(The MIT License)
|
44
|
-
|
45
|
-
Copyright (c) 2013 CarlosJHR64
|
46
|
-
|
47
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
-
a copy of this software and associated documentation files (the
|
49
|
-
'Software'), to deal in the Software without restriction, including
|
50
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
-
permit persons to whom the Software is furnished to do so, subject to
|
53
|
-
the following conditions:
|
54
|
-
|
55
|
-
The above copyright notice and this permission notice shall be
|
56
|
-
included in all copies or substantial portions of the Software.
|
57
|
-
|
58
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,144 +0,0 @@
|
|
1
|
-
class UserSpace
|
2
|
-
OPTIONS = {
|
3
|
-
config: 'config',
|
4
|
-
version: 'VERSION',
|
5
|
-
ext: nil,
|
6
|
-
parser: nil,
|
7
|
-
}
|
8
|
-
['JSON','YAML','Marshal'].each do |parser|
|
9
|
-
begin
|
10
|
-
OPTIONS[:parser] = Object.const_get parser
|
11
|
-
$stderr.puts "USER_SPACE will use #{parser} by default." if $VERBOSE
|
12
|
-
break
|
13
|
-
rescue NameError
|
14
|
-
$stderr.puts "#{parser} was not available for USER_SPACE." if $DEBUG
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
PARAMETERS = {
|
19
|
-
appname: File.basename($0),
|
20
|
-
appdir: nil, # Can't guess at this point yet?
|
21
|
-
xdgbases: ['CACHE', 'CONFIG', 'DATA'],
|
22
|
-
}
|
23
|
-
|
24
|
-
attr_reader :appname, :appdir, :xdgbases, :options
|
25
|
-
def initialize(parameters=PARAMETERS)
|
26
|
-
|
27
|
-
@appname = parameters[:appname] || PARAMETERS[:appname]
|
28
|
-
@appdir = parameters[:appdir] || PARAMETERS[:appdir]
|
29
|
-
@xdgbases = parameters[:xdgbases] || PARAMETERS[:xdgbases]
|
30
|
-
@options = OPTIONS.dup
|
31
|
-
|
32
|
-
unless @appdir
|
33
|
-
appdir = File.dirname File.dirname caller_locations(1,1)[0].path
|
34
|
-
appdir = File.dirname appdir if File.basename(appdir)=='lib'
|
35
|
-
@appdir = File.expand_path appdir
|
36
|
-
$stderr.puts "UserSpace#appdir=\"#{@appdir}\" # heuristics used" if $VERBOSE
|
37
|
-
end
|
38
|
-
|
39
|
-
# install with no overwrite
|
40
|
-
install(false)
|
41
|
-
end
|
42
|
-
|
43
|
-
def xdg_pairs
|
44
|
-
@xdgbases.each do |base|
|
45
|
-
xdg = XDG[base].to_s
|
46
|
-
userdir = File.join(xdg, @appname)
|
47
|
-
basedir = File.join @appdir, base.downcase
|
48
|
-
yield basedir, userdir
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Note that initialize will not overwrite anything.
|
53
|
-
# This overwrites the user's data directory with a fresh install.
|
54
|
-
# App should consider being nice about this,
|
55
|
-
# like warn the user or something.
|
56
|
-
def install(overwrite=true)
|
57
|
-
xdg_pairs do |basedir, userdir|
|
58
|
-
if File.exist?(userdir)
|
59
|
-
# Sanity check
|
60
|
-
raise "Not a directory: #{userdir}" unless File.directory?(userdir)
|
61
|
-
# Pre-existing directory.
|
62
|
-
# Return unless user wants to overwrite.
|
63
|
-
next unless overwrite
|
64
|
-
else
|
65
|
-
Dir.mkdir(userdir, 0700)
|
66
|
-
end
|
67
|
-
FileUtils.cp_r(Dir.glob("#{basedir}/*"), userdir) if File.directory? basedir
|
68
|
-
FileUtils.chmod_R 'og-rwx', userdir
|
69
|
-
FileUtils.chmod_R 'u+rwX', userdir
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def cachedir
|
74
|
-
File.join XDG['CACHE'].to_s, @appname
|
75
|
-
end
|
76
|
-
|
77
|
-
def configdir
|
78
|
-
File.join XDG['CONFIG'].to_s, @appname
|
79
|
-
end
|
80
|
-
|
81
|
-
def datadir
|
82
|
-
File.join XDG['DATA'].to_s, @appname
|
83
|
-
end
|
84
|
-
|
85
|
-
# Not really for public use.
|
86
|
-
def config_file_name
|
87
|
-
parser = @options[:parser]
|
88
|
-
ext = @options[:ext] || parser.to_s.downcase
|
89
|
-
basename = "#{@options[:config]}.#{ext}"
|
90
|
-
File.join XDG['CONFIG'].to_s, @appname, basename
|
91
|
-
end
|
92
|
-
|
93
|
-
# Not really for public use.
|
94
|
-
def version_file_name
|
95
|
-
File.join XDG['DATA'].to_s, @appname, @options[:version]
|
96
|
-
end
|
97
|
-
|
98
|
-
def config?
|
99
|
-
File.exist?(config_file_name)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Reads config
|
103
|
-
def config
|
104
|
-
p, d = @options[:parser], File.read(config_file_name)
|
105
|
-
p.load(d)
|
106
|
-
rescue
|
107
|
-
$stderr.puts $!.message if $VERBOSE
|
108
|
-
$stderr.puts $!.backtrace if $DEBUG
|
109
|
-
nil
|
110
|
-
end
|
111
|
-
|
112
|
-
# Saves config
|
113
|
-
def config=(obj)
|
114
|
-
p = @options[:parser]
|
115
|
-
d = (p.respond_to?(:pretty_generate))? p.pretty_generate(obj) : p.dump(obj)
|
116
|
-
File.open(config_file_name, 'w', 0600){|fh| fh.puts d}
|
117
|
-
end
|
118
|
-
|
119
|
-
def configures(hash)
|
120
|
-
if self.config? # file exists
|
121
|
-
self.config.each{|opt, value| hash[opt.to_sym] = value}
|
122
|
-
else
|
123
|
-
$stderr.puts config_file_name if $VERBOSE
|
124
|
-
self.config = hash
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def version?
|
129
|
-
File.exist?(version_file_name)
|
130
|
-
end
|
131
|
-
|
132
|
-
# This reads the data directory's version file
|
133
|
-
def version
|
134
|
-
File.read(version_file_name).strip
|
135
|
-
rescue
|
136
|
-
$stderr.puts $!.message if $VERBOSE
|
137
|
-
$stderr.puts $!.backtrace if $DEBUG
|
138
|
-
nil
|
139
|
-
end
|
140
|
-
|
141
|
-
def version=(v)
|
142
|
-
File.open(version_file_name, 'w', 0600){|fh| fh.puts v}
|
143
|
-
end
|
144
|
-
end
|
data/lib/user_space/version.rb
DELETED