ddollar-preferences 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
File without changes
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+
3
+ module Preferences
4
+ class Manager < Hash
5
+
6
+ attr_accessor :filename
7
+
8
+ def initialize(config_name, settings={})
9
+
10
+ @global = settings[:global] || false
11
+ @autosave = settings[:autosave] || false
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)
19
+ if File.exists?(@filename)
20
+ File.open(@filename, "r") do |file|
21
+ self.merge!(YAML.load(file))
22
+ end
23
+ end
24
+ end
25
+
26
+ def save
27
+ File.open(@filename, "w") do |file|
28
+ YAML.dump(self, file)
29
+ end
30
+ end
31
+
32
+ alias_method :default_writer, :[]=
33
+
34
+ def []=(key, value)
35
+ default_writer(key, value)
36
+ save if @autosave
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,43 @@
1
+ module Preferences
2
+ class Platform
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."
16
+ end
17
+
18
+ dir
19
+ end
20
+
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('~')
33
+ end
34
+
35
+ unless dir
36
+ raise EnvironmentException, "Can't determine a preferences directory."
37
+ end
38
+
39
+ dir
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ module Preferences
2
+ class EnvironmentException < Exception
3
+ end
4
+ end
5
+
6
+ require 'preferences/manager'
7
+ require 'preferences/platform'
File without changes
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ddollar-preferences
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Dollar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ddollar@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - lib/preferences
26
+ - lib/preferences/manager.rb
27
+ - lib/preferences/platform.rb
28
+ - lib/preferences.rb
29
+ - test/preferences.rb
30
+ - README
31
+ has_rdoc: true
32
+ homepage: http://peervoice.com/software/ruby/preferences
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project: preferences
53
+ rubygems_version: 1.0.1
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: An easy, cross-platform way to manage application configuration data
57
+ test_files: []
58
+