configural 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,130 @@
1
+ #--
2
+ #
3
+ # This file is one part of:
4
+ #
5
+ # Configural - Easy configuration file management
6
+ #
7
+ # Copyright (c) 2011 John Croisant
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to
14
+ # permit persons to whom the Software is furnished to do so, subject to
15
+ # the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be
18
+ # included in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+ #++
29
+
30
+ require 'rbconfig'
31
+
32
+ module Configural
33
+
34
+ class Platform
35
+ def self.inherited(subclass)
36
+ @subclasses ||= []
37
+ @subclasses << subclass
38
+ end
39
+
40
+ def self.get_platform( app )
41
+ platform = @subclasses.reverse.find { |subclass|
42
+ subclass.match?( app )
43
+ }
44
+ unless platform
45
+ raise 'Sorry, your operating system is not yet supported.'
46
+ end
47
+ platform
48
+ end
49
+
50
+ def self.match?( app )
51
+ raise 'Method not implemented for base class.'
52
+ end
53
+
54
+
55
+ def initialize( app )
56
+ @app = app
57
+ end
58
+
59
+ def cache_path
60
+ raise 'Method not implemented for base class.'
61
+ end
62
+
63
+ def config_path
64
+ raise 'Method not implemented for base class.'
65
+ end
66
+
67
+ def data_path
68
+ raise 'Method not implemented for base class.'
69
+ end
70
+ end
71
+
72
+
73
+ class LinuxPlatform < Platform
74
+ def self.match?( app )
75
+ true if /linux/ =~ RbConfig::CONFIG['host_os']
76
+ end
77
+
78
+ def cache_path
79
+ File.join( ENV['HOME'], '.cache', @app.name )
80
+ end
81
+
82
+ def config_path
83
+ File.join( ENV['HOME'], '.config', @app.name )
84
+ end
85
+
86
+ def data_path
87
+ File.join( ENV['HOME'], '.local', 'share', @app.name )
88
+ end
89
+ end
90
+
91
+
92
+ class MacPlatform < Platform
93
+ def self.match?( app )
94
+ true if /darwin/ =~ RbConfig::CONFIG['host_os']
95
+ end
96
+
97
+ def cache_path
98
+ File.join( ENV['HOME'], 'Library', 'Caches', @app.name )
99
+ end
100
+
101
+ def config_path
102
+ File.join( ENV['HOME'], 'Library', 'Preferences', @app.name )
103
+ end
104
+
105
+ def data_path
106
+ File.join( ENV['HOME'], 'Library',
107
+ 'Application Support', @app.name )
108
+ end
109
+ end
110
+
111
+
112
+ class WindowsPlatform < Platform
113
+ def self.match?( app )
114
+ true if /mswin|mingw/ =~ RbConfig::CONFIG['host_os']
115
+ end
116
+
117
+ def cache_path
118
+ File.join( ENV['APPDATA'], @app.name, 'Cache' )
119
+ end
120
+
121
+ def config_path
122
+ File.join( ENV['APPDATA'], @app.name, 'Config' )
123
+ end
124
+
125
+ def data_path
126
+ File.join( ENV['APPDATA'], @app.name, 'Data' )
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,71 @@
1
+ #--
2
+ #
3
+ # This file is one part of:
4
+ #
5
+ # Configural - Easy configuration file management
6
+ #
7
+ # Copyright (c) 2011 John Croisant
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to
14
+ # permit persons to whom the Software is furnished to do so, subject to
15
+ # the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be
18
+ # included in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+ #++
29
+
30
+
31
+ module Configural
32
+
33
+ class User
34
+ attr_accessor :platform
35
+
36
+ def initialize( app )
37
+ @app = app
38
+ @platform = Configural::Platform.get_platform(app).new(app)
39
+ end
40
+
41
+ def config
42
+ @config ||= Configural::Config.new(self)
43
+ end
44
+
45
+ def config_path
46
+ @platform.config_path
47
+ end
48
+
49
+ def cache
50
+ @cache ||= Configural::Cache.new(self)
51
+ end
52
+
53
+ def cache_path
54
+ @platform.cache_path
55
+ end
56
+
57
+ def data
58
+ @data ||= Configural::Data.new(self)
59
+ end
60
+
61
+ def data_path
62
+ @platform.data_path
63
+ end
64
+
65
+ def save_all
66
+ @config.save_all if @config
67
+ self
68
+ end
69
+ end
70
+
71
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configural
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Croisant
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: john@croisant.net
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - NEWS.rdoc
21
+ - README.rdoc
22
+ - lib/configural/app.rb
23
+ - lib/configural/autosave.rb
24
+ - lib/configural/config/file_base.rb
25
+ - lib/configural/config/json_file.rb
26
+ - lib/configural/config/plist_file.rb
27
+ - lib/configural/config/sdl_file.rb
28
+ - lib/configural/config/yaml_file.rb
29
+ - lib/configural/config.rb
30
+ - lib/configural/data.rb
31
+ - lib/configural/platform.rb
32
+ - lib/configural/user.rb
33
+ - lib/configural.rb
34
+ - ChangeLog.txt
35
+ homepage: http://github.com/jacius/configural/
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '1.8'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Easy configuration file management
59
+ test_files: []