ddollar-preferences 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,17 +5,25 @@ module Preferences
5
5
 
6
6
  attr_accessor :filename
7
7
 
8
- def initialize(config_name, settings={})
8
+ def initialize(name, settings={})
9
9
 
10
- @global = settings[:global] || false
10
+ @type = settings[:type] || :user
11
11
  @autosave = settings[:autosave] || false
12
12
 
13
- directory = @global ? Platform::config_directory_global :
14
- Platform::config_directory_user
15
-
16
- config_file = @global ? "#{config_name}.conf" : ".#{config_name}"
17
-
18
- @filename = File.join(directory, config_file)
13
+ directory = case @type
14
+ when :system then Platform::config_directory_system
15
+ when :user then Platform::config_directory_user
16
+ when :test then Platform::config_directory_test
17
+ end
18
+
19
+ file = case @type
20
+ when :system then "#{name}.conf"
21
+ when :user then ".#{name}"
22
+ when :test then "#{name}.preferences.test"
23
+ end
24
+
25
+ @filename = File.join(directory, file)
26
+
19
27
  if File.exists?(@filename)
20
28
  File.open(@filename, "r") do |file|
21
29
  self.merge!(YAML.load(file))
@@ -1,41 +1,30 @@
1
1
  module Preferences
2
2
  class Platform
3
3
 
4
- def Platform.config_directory_global
5
- case RUBY_PLATFORM
6
- when /win32/
7
- raise EnvironmentException, "Don't yet know how to get a global Windows preferences directory"
8
-
9
- else
10
- dir = '/etc'
11
-
12
- end
13
-
14
- unless dir
15
- raise EnvironmentException, "Can't determine a preferences directory."
4
+ def self.config_directory_system
5
+ dir = case RUBY_PLATFORM
6
+ when /win32/ then nil
7
+ else '/etc'
16
8
  end
17
-
9
+ raise EnvironmentException, "Can't determine a preferences directory." unless dir
18
10
  dir
19
11
  end
20
12
 
21
- def Platform.config_directory_user
22
- case RUBY_PLATFORM
23
- when /win32/
24
- dir =
25
- ENV['APPDATA'] || # C:\Documents and Settings\name\Application Data
26
- ENV['USERPROFILE'] || # C:\Documents and Settings\name
27
- ENV['HOME']
28
-
29
- else
30
- dir =
31
- ENV['HOME'] ||
32
- File.expand_path('~')
13
+ def self.config_directory_user
14
+ dir = case RUBY_PLATFORM
15
+ when /win32/ then ENV['APPDATA'] || ENV['USERPROFILE'] || ENV['HOME']
16
+ else ENV['HOME'] || File.expand_path('~')
33
17
  end
18
+ raise EnvironmentException, "Can't determine a preferences directory." unless dir
19
+ dir
20
+ end
34
21
 
35
- unless dir
36
- raise EnvironmentException, "Can't determine a preferences directory."
22
+ def self.config_directory_test
23
+ dir = case RUBY_PLATFORM
24
+ when /win32/ then nil
25
+ else '/tmp'
37
26
  end
38
-
27
+ raise EnvironmentException, "Can't determine a preferences directory." unless dir
39
28
  dir
40
29
  end
41
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddollar-preferences
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Dollar
@@ -22,11 +22,18 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README
24
24
  files:
25
+ - doc/output
26
+ - doc/output/coverage
27
+ - doc/output/coverage/index.html
28
+ - doc/output/coverage/lib-preferences-manager_rb.html
29
+ - doc/output/coverage/lib-preferences-platform_rb.html
30
+ - doc/output/coverage/lib-preferences_rb.html
31
+ - doc/output/coverage/spec-manager_spec_rb.html
32
+ - doc/output/coverage/spec-platform_spec_rb.html
25
33
  - lib/preferences
26
34
  - lib/preferences/manager.rb
27
35
  - lib/preferences/platform.rb
28
36
  - lib/preferences.rb
29
- - test/preferences.rb
30
37
  - README
31
38
  has_rdoc: true
32
39
  homepage: http://peervoice.com/software/ruby/preferences
data/test/preferences.rb DELETED
File without changes