user_space 0.3.1 → 3.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 149e88ebcb48a9ca714ad14566702034e351b2a3
4
- data.tar.gz: 0f235cd46600224046f4837c2569ddf07c1c01c5
2
+ SHA256:
3
+ metadata.gz: 1dfcc971479291e90e318bd01ba58aa13ebfd8879b8cea95e308b37530933393
4
+ data.tar.gz: c0bccd867a3a6aa2ab2a6af9280391e6e6c0393b1f9df9664dd9f0ac7f0ccdc0
5
5
  SHA512:
6
- metadata.gz: e94d27a7b3eb42a40190310db8ec1a5814028edbe78e082257a10a2d7f21a0507ebb4cab42bb749420308a40f5f38bc8dca144a818f6f464bebfbec239b709ca
7
- data.tar.gz: 4a366e41156a30c6956da85cd56e7695bd1c8866ba215eb5568e74b6e615bee31939e0445a0ba9786a174a3bb787eee5d549c93f822897abddca78c4da48c9ba
6
+ metadata.gz: a22b5d23502cb1216d444510f1fe0474125a9d5b9ce3bfd87908516071f1efc59290ce367eda718bfb259bc5f1306796cb4e41f075f7b9b6b7623eee7a457fab
7
+ data.tar.gz: 210fad38ba6a7c41852176660b59ee0301eec0ad193cf04b9cc7273c8de0601942a6b2a9415990379ed59515e933c4cc576c4072a7a9aa52f28e290fa0180403
@@ -0,0 +1,61 @@
1
+ # UserSpace
2
+
3
+ * [VERSION 3.0.3](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 app's XDG features: app's cache, config, and data directories.
10
+
11
+ ## SYNOPSIS:
12
+
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)
33
+
34
+ ## INSTALL:
35
+
36
+ sudo gem install user_space
37
+
38
+ ## LICENSE:
39
+
40
+ (The MIT License)
41
+
42
+ Copyright (c) 2020 CarlosJHR64
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,8 +1,132 @@
1
- require 'English'
2
1
  require 'fileutils'
3
- require 'json' # default parser
4
2
  require 'xdg'
5
- require 'user_space/version.rb'
6
- require 'user_space/user_space.rb'
7
3
  # Requires:
8
4
  #`ruby`
5
+
6
+ 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
14
+
15
+ 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
+ )
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
+ xdg = XDG[base].to_s
31
+ userdir = File.join(xdg, @appname)
32
+ basedir = File.join @appdir, base.downcase
33
+ yield basedir, userdir
34
+ end
35
+ end
36
+
37
+ # Note that initialize will not overwrite anything.
38
+ # This overwrites the user's data directory with a fresh install.
39
+ # App should consider being nice about this,
40
+ # like warn the user or something.
41
+ def install(overwrite=true)
42
+ xdg_pairs do |basedir, userdir|
43
+ if File.exist?(userdir)
44
+ # Sanity check
45
+ raise "Not a directory: #{userdir}" unless File.directory?(userdir)
46
+ # Pre-existing directory.
47
+ # Return unless user wants to overwrite.
48
+ next unless overwrite
49
+ else
50
+ Dir.mkdir(userdir, 0700)
51
+ end
52
+ if File.directory? basedir
53
+ Dir.glob("#{basedir}/**/*").each do |src|
54
+ dest = src.sub(basedir, userdir)
55
+ if File.directory? src
56
+ Dir.mkdir dest unless File.exist? dest
57
+ else
58
+ FileUtils.cp src, dest
59
+ end
60
+ FileUtils.chmod('u+rwX,go-rwx', dest)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def cachedir
67
+ File.join XDG['CACHE'].to_s, @appname
68
+ end
69
+
70
+ def configdir
71
+ File.join XDG['CONFIG'].to_s, @appname
72
+ end
73
+
74
+ def datadir
75
+ File.join XDG['DATA'].to_s, @appname
76
+ end
77
+
78
+ # Not really for public use.
79
+ def config_file_name
80
+ File.join XDG['CONFIG'].to_s, @appname, "#{@config}.#{@ext}"
81
+ end
82
+
83
+ # Not really for public use.
84
+ def version_file_name
85
+ File.join XDG['DATA'].to_s, @appname, 'VERSION'
86
+ end
87
+
88
+ def config?
89
+ File.exist?(config_file_name)
90
+ end
91
+
92
+ # Reads config
93
+ def config
94
+ @parser.load File.read(config_file_name)
95
+ rescue
96
+ $stderr.puts $!.message if $VERBOSE
97
+ $stderr.puts $!.backtrace if $DEBUG
98
+ nil
99
+ end
100
+
101
+ # Saves config
102
+ def config=(obj)
103
+ dump = (@parser.respond_to?(:pretty_generate))? @parser.pretty_generate(obj) : @parser.dump(obj)
104
+ File.open(config_file_name, 'w', 0600){|fh|fh.puts dump}
105
+ end
106
+
107
+ def configures(hash)
108
+ if self.config? # file exists
109
+ self.config.each{|opt, value| hash[opt.to_sym] = value}
110
+ else
111
+ $stderr.puts config_file_name if $VERBOSE
112
+ self.config = hash
113
+ end
114
+ end
115
+
116
+ def version?
117
+ File.exist?(version_file_name)
118
+ end
119
+
120
+ # This reads the data directory's version file
121
+ def version
122
+ File.read(version_file_name).strip
123
+ rescue
124
+ $stderr.puts $!.message if $VERBOSE
125
+ $stderr.puts $!.backtrace if $DEBUG
126
+ nil
127
+ end
128
+
129
+ def version=(v)
130
+ File.open(version_file_name, 'w', 0600){|fh| fh.puts v}
131
+ end
132
+ end
metadata CHANGED
@@ -1,102 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: user_space
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
- - CarlosJHR64
7
+ - carlosjhr64
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-16 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xdg
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.2'
20
- - - ">="
17
+ - - '='
21
18
  - !ruby/object:Gem::Version
22
19
  version: 2.2.3
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.2'
30
- - - ">="
24
+ - - '='
31
25
  - !ruby/object:Gem::Version
32
26
  version: 2.2.3
33
- - !ruby/object:Gem::Dependency
34
- name: rainbow
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '1.99'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.99.1
43
- type: :development
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '1.99'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 1.99.1
53
- - !ruby/object:Gem::Dependency
54
- name: test-unit
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '2.5'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 2.5.5
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '2.5'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 2.5.5
73
- description: |
74
- Automates certain XDG features.
27
+ description: 'Maintains the app''s XDG features: app''s cache, config, and data directories.
28
+
29
+ '
75
30
  email: carlosjhr64@gmail.com
76
31
  executables: []
77
32
  extensions: []
78
- extra_rdoc_files:
79
- - README.rdoc
33
+ extra_rdoc_files: []
80
34
  files:
81
- - History.txt
82
- - README.rdoc
83
- - TODO.txt
84
- - data/VERSION
85
- - features/main.feature
86
- - features/step_definitions/main_steps.rb
35
+ - README.md
87
36
  - lib/user_space.rb
88
- - lib/user_space/user_space.rb
89
- - lib/user_space/version.rb
90
- - test/user_space.rb
91
- - user_space.gemspec
92
37
  homepage: https://github.com/carlosjhr64/user_space
93
38
  licenses:
94
39
  - MIT
95
40
  metadata: {}
96
41
  post_install_message:
97
- rdoc_options:
98
- - "--main"
99
- - README.rdoc
42
+ rdoc_options: []
100
43
  require_paths:
101
44
  - lib
102
45
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -110,10 +53,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
53
  - !ruby/object:Gem::Version
111
54
  version: '0'
112
55
  requirements:
113
- - 'ruby: ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]'
114
- rubyforge_project:
115
- rubygems_version: 2.2.0
56
+ - 'ruby: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]'
57
+ rubygems_version: 3.1.2
116
58
  signing_key:
117
59
  specification_version: 4
118
- summary: Automates certain XDG features.
60
+ summary: 'Maintains the app''s XDG features: app''s cache, config, and data directories.'
119
61
  test_files: []
@@ -1,9 +0,0 @@
1
- === 0.0.0 / 2013-12-21 09:33:10 -0800
2
- === 0.0.0 / 2013-12-22 15:18:15 -0800
3
- 2421f13574dd2ad78d6cc591e52b4261 pkg/user_space-0.0.0.gem
4
- === 0.1.0 / 2013-12-30 11:51:13 -0800
5
- c0014415ced058f3b79910f5c52bfe1e pkg/user_space-0.1.0.gem
6
- === 0.2.0 / 2014-01-02 10:12:47 -0800
7
- 1cd8d6d59f08ff03b32c895ee254ca14 pkg/user_space-0.2.0.gem
8
- === 0.3.0 / 2014-01-16 08:17:03 -0800
9
- b2df08bdd1e6f0be634109602ef1c63e pkg/user_space-0.3.0.gem
@@ -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 = USER_SPACE::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.
data/TODO.txt DELETED
@@ -1,5 +0,0 @@
1
- == File List
2
-
3
- TODO: Come up with some good cucumber tests.
4
- features/step_definitions/main_steps.rb, #2
5
-
@@ -1 +0,0 @@
1
- 1.20.300
@@ -1,9 +0,0 @@
1
- @main
2
- Feature: Main Feature
3
-
4
- Background:
5
- * Given main feature
6
-
7
- Scenario:
8
- * When main feature
9
- * Then main feature
@@ -1,18 +0,0 @@
1
- require 'rainbow'
2
- # TODO: Come up with some good cucumber tests.
3
- Given /^(\w+) (.*)$/ do |given, condition|
4
- condition.strip!
5
- case given
6
- when 'Given'
7
- #raise "'Given' form not defined."
8
- STDERR.puts "Need to come up with some cucumber tests".color(:blue)
9
- when 'When'
10
- #raise "'When' form not defined."
11
- STDERR.puts "Need to come up with some cucumber tests".color(:blue)
12
- when 'Then'
13
- #raise "'Then' form not defined."
14
- STDERR.puts "Need to come up with some cucumber tests".color(:blue)
15
- else
16
- raise "'#{given}' form not defined."
17
- end
18
- end
@@ -1,130 +0,0 @@
1
- module USER_SPACE
2
- class UserSpace
3
-
4
- OPTIONS = {:config => 'config',
5
- :parser => JSON,
6
- :ext => nil,
7
- :version => 'VERSION'}
8
-
9
- PARAMETERS = {:appname => File.basename($PROGRAM_NAME),
10
- :appdir => nil, # Can't guess at this point yet?
11
- :xdgbases => ['CACHE', 'CONFIG', 'DATA']}
12
-
13
- attr_accessor :trace, :verbose
14
- attr_reader :appname, :appdir, :xdgbases, :options
15
- def initialize(parameters=PARAMETERS)
16
-
17
- @appname = parameters[:appname] || PARAMETERS[:appname]
18
- @appdir = parameters[:appdir] || PARAMETERS[:appdir]
19
- @xdgbases = parameters[:xdgbases] || PARAMETERS[:xdgbases]
20
- @options = OPTIONS
21
-
22
- unless @appdir
23
- appdir = File.dirname File.dirname caller.first.split(/:/,2).first
24
- @appdir = File.expand_path appdir
25
- end
26
-
27
- # install with no overwrite
28
- install(false)
29
- end
30
-
31
- def xdg_pairs
32
- @xdgbases.each do |base|
33
- xdg = XDG[base].to_s
34
- userdir = File.join(xdg, @appname)
35
- basedir = File.join @appdir, base.downcase
36
- yield basedir, userdir
37
- end
38
- end
39
-
40
- # Note that initialize will not overwrite anything.
41
- # This overwrites the user's data directory with a fresh install.
42
- # App should consider being nice about this,
43
- # like warn the user or something.
44
- def install(overwrite=true)
45
- xdg_pairs do |basedir, userdir|
46
- if File.exist?(userdir)
47
- # Sanity check
48
- raise "Not a directory: #{userdir}" unless File.directory?(userdir)
49
- # Pre-existing directory.
50
- # Return unless user wants to overwrite.
51
- next unless overwrite
52
- else
53
- Dir.mkdir(userdir, 0700)
54
- end
55
- FileUtils.cp_r(Dir.glob("#{basedir}/*"), userdir) if File.directory? basedir
56
- FileUtils.chmod_R 'og-rwx', userdir
57
- FileUtils.chmod_R 'u+rwX', userdir
58
- end
59
- end
60
-
61
- def cachedir
62
- File.join XDG['CACHE'].to_s, @appname
63
- end
64
-
65
- def configdir
66
- File.join XDG['CONFIG'].to_s, @appname
67
- end
68
-
69
- def datadir
70
- File.join XDG['DATA'].to_s, @appname
71
- end
72
-
73
- # Not really for public use.
74
- def config_file_name(options=@options)
75
- parser = options[:parser]
76
- ext = options[:ext] || parser.to_s.downcase
77
- basename = "#{options[:config]}.#{ext}"
78
- File.join XDG['CONFIG'].to_s, @appname, basename
79
- end
80
-
81
- # Not really for public use.
82
- def version_file_name
83
- File.join XDG['DATA'].to_s, @appname, @options[:version]
84
- end
85
-
86
- def config?(options=@options)
87
- File.exist?(config_file_name(options))
88
- end
89
-
90
- # Reads config
91
- def config(options=@options)
92
- options[:parser].parse File.read(config_file_name(options))
93
- rescue
94
- trace.puts $!.message if trace
95
- vebose.puts $!.backtrace if verbose
96
- nil
97
- end
98
-
99
- # Saves config
100
- def config=(obj, options=@options)
101
- File.open(config_file_name, 'w', 0600){|fh| fh.puts options[:parser].pretty_generate obj}
102
- end
103
-
104
- def configures(hash)
105
- if self.config? # file exists
106
- self.config.each{|opt, value| hash[opt.to_sym] = value}
107
- else
108
- trace.puts config_file_name if trace
109
- self.config = hash
110
- end
111
- end
112
-
113
- def version?
114
- File.exist?(version_file_name)
115
- end
116
-
117
- # This reads the data directory's version file
118
- def version
119
- File.read(version_file_name).strip
120
- rescue
121
- trace.puts $!.message if trace
122
- vebose.puts $!.backtrace if verbose
123
- nil
124
- end
125
-
126
- def version=(v)
127
- File.open(version_file_name, 'w', 0600){|fh| fh.puts v}
128
- end
129
- end
130
- end
@@ -1,3 +0,0 @@
1
- module USER_SPACE
2
- VERSION = '0.3.1'
3
- end
@@ -1,129 +0,0 @@
1
- require 'test/unit'
2
- require 'tmpdir'
3
- TMPDIR = Dir.mktmpdir
4
- Dir.mkdir File.join TMPDIR, '.cache'
5
- Dir.mkdir File.join TMPDIR, '.config'
6
- Dir.mkdir File.join TMPDIR, '.local'
7
- Dir.mkdir File.join TMPDIR, '.local', 'share'
8
- APPNAME = 'ima2awesome'
9
-
10
- ENV['HOME'] = TMPDIR
11
- $0 = APPNAME
12
-
13
- # Needed to setup the enviroment first, now...
14
- require 'user_space'
15
-
16
- class TestUserSpace < Test::Unit::TestCase
17
-
18
- include USER_SPACE
19
-
20
- def test_user_space_version
21
- assert_equal('0.3.1', VERSION)
22
- end
23
-
24
- def test_user_space_constants
25
- assert_equal 'config', UserSpace::OPTIONS[:config]
26
- assert_equal JSON, UserSpace::OPTIONS[:parser]
27
- assert_equal 'VERSION', UserSpace::OPTIONS[:version]
28
- assert_nil UserSpace::OPTIONS[:ext]
29
-
30
- assert_equal 'ima2awesome', UserSpace::PARAMETERS[:appname]
31
-
32
- xdgbases = UserSpace::PARAMETERS[:xdgbases]
33
- assert xdgbases.include? 'CACHE'
34
- assert xdgbases.include? 'CONFIG'
35
- assert xdgbases.include? 'DATA'
36
- end
37
-
38
- def test_user_space_new
39
- userspace = nil
40
- assert_nothing_raised(Exception){userspace = UserSpace.new}
41
-
42
- assert_equal(APPNAME, userspace.appname)
43
-
44
- dirname = File.dirname File.dirname File.expand_path __FILE__
45
- assert_equal(dirname, userspace.appdir)
46
-
47
- xdgbases = userspace.xdgbases
48
- assert(userspace.xdgbases.include?('CACHE'))
49
- assert(userspace.xdgbases.include?('CONFIG'))
50
- assert(userspace.xdgbases.include?('DATA'))
51
-
52
- count = 0
53
- userspace.xdg_pairs do |basedir, userdir|
54
- count += 1
55
- assert(File.directory?(userdir))
56
- refute_nil(userdir=~/\/ima2awesome$/)
57
- refute_nil(basedir=~/user_space\/((data)|(config)|(cache))$/)
58
- end
59
- assert_equal(3, count)
60
-
61
- options = userspace.options
62
- assert_equal('config', options[:config])
63
- assert_equal('VERSION', options[:version])
64
- assert_equal(JSON, options[:parser])
65
- assert_nil(options[:ext])
66
-
67
- cachedir, configdir, datadir = userspace.cachedir, userspace.configdir, userspace.datadir
68
- assert File.exist? cachedir
69
- assert File.exist? configdir
70
- assert File.exist? datadir
71
-
72
- version = File.read('data/VERSION').strip
73
- assert_equal version, userspace.version
74
-
75
- config_file_name = userspace.config_file_name
76
- refute File.exist? config_file_name
77
- config1 = {'a'=>"A", 'b'=>"B"}
78
- userspace.config = config1
79
- assert File.exist? config_file_name
80
- config2 = JSON.parse File.read config_file_name
81
- assert_equal config1, config2
82
-
83
- # Overwrite version file...
84
- version_file_name = userspace.version_file_name
85
- File.open(version_file_name, 'w'){|fh|fh.puts 'A.B.C'}
86
- # Now we get the version given to the file:
87
- assert_equal 'A.B.C', userspace.version
88
- # Which is different from the initial version
89
- refute version == 'A.B.C'
90
-
91
- # But we can re-fresh our install
92
- assert_nothing_raised(Exception){userspace.install}
93
- # Now we have our initial version back
94
- assert_equal version, userspace.version
95
-
96
- [config_file_name, version_file_name].each do |fn|
97
- stat = File.stat(fn)
98
- assert_equal stat.mode.to_s(8), '100600'
99
- end
100
-
101
- [cachedir, configdir, datadir].each do |dn|
102
- stat = File.stat(dn)
103
- assert_equal stat.mode.to_s(8), '40700'
104
- end
105
-
106
- assert userspace.version?
107
- assert_nothing_raised(Exception){ userspace.version='Fantastico' }
108
- assert_equal userspace.version, 'Fantastico'
109
-
110
- # testing configures
111
- config_file_name = userspace.config_file_name
112
- File.unlink config_file_name if File.exist? config_file_name
113
- config1 = {:a=>'A', :b=>'B'}
114
- refute File.exist? config_file_name
115
- userspace.configures(config1)
116
- # Here, it copies to file.
117
- assert File.exist? config_file_name
118
- # And config1 remains unchanged.
119
- assert_equal(config1[:a], 'A')
120
- assert_equal(config1[:b], 'B')
121
- assert_equal(config1[:c], nil)
122
- config2 = {:a=>'AAA', :c=>'CCC'}
123
- # Here, config2 is overwritten with config1 from file.
124
- userspace.configures(config2)
125
- assert_equal(config2[:a], 'A') # overwritten
126
- assert_equal(config2[:b], 'B') # padded up
127
- assert_equal(config2[:c], 'CCC') # Original value
128
- end
129
- end
@@ -1,45 +0,0 @@
1
- Gem::Specification.new do |s|
2
-
3
- s.name = 'user_space'
4
- s.version = '0.3.1'
5
-
6
- s.homepage = 'https://github.com/carlosjhr64/user_space'
7
-
8
- s.author = 'CarlosJHR64'
9
- s.email = 'carlosjhr64@gmail.com'
10
-
11
- s.date = '2014-01-16'
12
- s.licenses = ['MIT']
13
-
14
- s.description = <<DESCRIPTION
15
- Automates certain XDG features.
16
- DESCRIPTION
17
-
18
- s.summary = <<SUMMARY
19
- Automates certain XDG features.
20
- SUMMARY
21
-
22
- s.extra_rdoc_files = ['README.rdoc']
23
- s.rdoc_options = ["--main", "README.rdoc"]
24
-
25
- s.require_paths = ["lib"]
26
- s.files = %w(
27
- History.txt
28
- README.rdoc
29
- TODO.txt
30
- data/VERSION
31
- features/main.feature
32
- features/step_definitions/main_steps.rb
33
- lib/user_space.rb
34
- lib/user_space/user_space.rb
35
- lib/user_space/version.rb
36
- test/user_space.rb
37
- user_space.gemspec
38
- )
39
-
40
- s.add_runtime_dependency 'xdg', '~> 2.2', '>= 2.2.3'
41
- s.add_development_dependency 'rainbow', '~> 1.99', '>= 1.99.1'
42
- s.add_development_dependency 'test-unit', '~> 2.5', '>= 2.5.5'
43
- s.requirements << 'ruby: ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]'
44
-
45
- end