parseconfig 0.5.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/Changelog +6 -0
  2. data/LICENSE +3 -1
  3. data/README.md +75 -0
  4. data/lib/parseconfig.rb +13 -29
  5. metadata +9 -11
  6. data/README +0 -57
  7. data/demo.conf +0 -11
  8. data/demo.rb +0 -66
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ Tue Jun 12, 2012 - v1.0.0
2
+ - Resolved Issue #3, Config files not closed properly.
3
+ - Resolved Issue #7, Added basic rspec testing
4
+ - Resolved Issue #5, Readded support for array like access
5
+ - Removed deprecated function get_value()
6
+
1
7
  Sat Feb 27, 2010 - v0.5.2
2
8
  - Re-releasing under MIT License.
3
9
  - Fixed issue with the add() method where if you added a group outside
data/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
+
1
2
  The MIT License:
2
3
 
3
- Copyright (c) 2006 BJ Dierkes
4
+ Copyright (c) 2006-2012 BJ Dierkes
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +20,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
20
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
21
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
22
  THE SOFTWARE.
23
+
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ Ruby ParseConfig Library
2
+ ========================
3
+
4
+ ParseConfig provides simple parsing of standard configuration files in the
5
+ form of 'param = value'. It also supports nested [group] sections.
6
+
7
+ [![Continuous Integration Status](https://secure.travis-ci.org/derks/ruby-parseconfig.png)](http://travis-ci.org/derks/ruby-parseconfig)
8
+
9
+ Installation
10
+ ------------
11
+
12
+ $ sudo gem install parseconfig
13
+
14
+ Usage
15
+ -----
16
+
17
+ An example configuration file might look like:
18
+
19
+ # Example Config
20
+ param1 = value1
21
+ param2 = value2
22
+
23
+ [group1]
24
+ group1_param1 = group1_value1
25
+ group1_param2 = group1_value2
26
+
27
+ [group2]
28
+ group2_param1 = group2_value1
29
+ group2_param2 = group2_value2
30
+
31
+
32
+ Access it with ParseConfig:
33
+
34
+ >> require('parseconfig.rb')
35
+ => true
36
+
37
+ >> config = ParseConfig.new('/path/to/config/file')
38
+ => #<ParseConfig:0x102410908
39
+ @config_file="example.conf",
40
+ @groups=["group1", "group2"],
41
+ @params={
42
+ "param1"=>"value1"
43
+ "param2"=>"value2",
44
+ "group1"=>{
45
+ "param1"=>"value1"
46
+ "param2"=>"value2",
47
+ },
48
+ "group2"=>{
49
+ "param1"=>"value1"
50
+ "param2"=>"value2",
51
+ },
52
+ }
53
+ >
54
+
55
+ >> config.get_params()
56
+ => ["param1", "param2", "group1", "group2"]
57
+
58
+ >> config['param1']
59
+ => "value1"
60
+
61
+ >> config.get_groups()
62
+ => ["group1", "group2"]
63
+
64
+ >> config['group1']
65
+ => {"group1_param1"=>"group1_value1", "group1_param2"=>"group1_value2"}
66
+
67
+ >> config['group1']['group1_param1']
68
+ => "group1_value1"
69
+
70
+
71
+ License
72
+ -------
73
+
74
+ The ParseConfig library is Open Source and distributed under the MIT license.
75
+ Please see the LICENSE file included with this software.
data/lib/parseconfig.rb CHANGED
@@ -1,9 +1,8 @@
1
- # $Id: parseconfig.rb 37 2008-02-29 07:27:33Z wdierkes $
2
1
  #
3
- # Author:: BJ Dierkes <wdierkes@5dollarwhitebox.org>
4
- # Copyright:: Copyright (c) 2006,2009 5dollarwhitebox.org
2
+ # Author:: BJ Dierkes <derks@bjdierkes.com>
3
+ # Copyright:: Copyright (c) 2006,2012 BJ Dierkes
5
4
  # License:: MIT
6
- # URL:: http://www.5dollarwhitebox.org
5
+ # URL:: https://github.com/derks/ruby-parseconfig
7
6
  #
8
7
 
9
8
  # This class was written to simplify the parsing of configuration
@@ -19,7 +18,7 @@
19
18
 
20
19
  class ParseConfig
21
20
 
22
- Version = '0.5.2'
21
+ Version = '0.5.3'
23
22
 
24
23
  attr_accessor :config_file, :params, :groups
25
24
 
@@ -54,7 +53,7 @@ class ParseConfig
54
53
  # The config is top down.. anything after a [group] gets added as part
55
54
  # of that group until a new [group] is found.
56
55
  group = nil
57
- open(self.config_file).each do |line|
56
+ open(self.config_file) { |f| f.each do |line|
58
57
  line.strip!
59
58
  unless (/^\#/.match(line))
60
59
  if(/\s*=\s*/.match(line))
@@ -84,7 +83,7 @@ class ParseConfig
84
83
 
85
84
  end
86
85
  end
87
- end
86
+ end }
88
87
  end
89
88
 
90
89
  # This method will provide the value held by the object "@param"
@@ -93,7 +92,13 @@ class ParseConfig
93
92
  #
94
93
  # DEPRECATED - will be removed in future versions
95
94
  #
96
- def get_value(param)
95
+ #def get_value(param)
96
+ # puts "ParseConfig Deprecation Warning: get_value() is deprecated."
97
+ # return self.params[param]
98
+ #end
99
+
100
+ # This method is a shortcut to accessing the @params variable
101
+ def [](param)
97
102
  return self.params[param]
98
103
  end
99
104
 
@@ -106,27 +111,6 @@ class ParseConfig
106
111
  def get_groups()
107
112
  return self.groups
108
113
  end
109
-
110
- # This method is simple. Should you need to override a value
111
- # dynamically, use override_value(param, value) where 'param' is
112
- # the name of the paramater in the config file.
113
- #
114
- # DEPRECATED - will be removed in future versions.
115
- #
116
- def override_value(param, value)
117
- #self.instance_variable_set("@#{param}", value)
118
- raise RuntimeError, "override_value() is deprecated as of 0.5.1"
119
- end
120
-
121
- # This method will set the value of '@param' to nil (not in the config
122
- # file, only in the app).
123
- #
124
- # DEPRECATED - will be removed in future versions.
125
- #
126
- def nil_value(param)
127
- #self.instance_variable_set("@#{param}", nil)
128
- raise RuntimeError, "nil_value() is deprecated as of 0.5.1"
129
- end
130
114
 
131
115
  # This method adds an element to the config object (not the config file)
132
116
  # By adding a Hash, you create a new group
metadata CHANGED
@@ -3,10 +3,10 @@ name: parseconfig
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 5
8
- - 2
9
- version: 0.5.2
8
+ - 0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - BJ Dierkes
@@ -14,12 +14,12 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-27 00:00:00 -06:00
17
+ date: 2012-06-12 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: ParseConfig provides simple parsing of standard *nix style config files.
22
- email: wdierkes@5dollarwhitebox.org
21
+ description: ParseConfig provides simple parsing of standard configuration files in the form of 'param = value'. It also supports nested [group] sections.
22
+ email: derks@bjdierkes.com
23
23
  executables: []
24
24
 
25
25
  extensions: []
@@ -27,14 +27,12 @@ extensions: []
27
27
  extra_rdoc_files: []
28
28
 
29
29
  files:
30
- - README
30
+ - README.md
31
31
  - Changelog
32
32
  - LICENSE
33
- - demo.rb
34
- - demo.conf
35
33
  - lib/parseconfig.rb
36
34
  has_rdoc: true
37
- homepage: http://www.5dollarwhitebox.org/
35
+ homepage: http://github.com/derks/ruby-parseconfig/
38
36
  licenses: []
39
37
 
40
38
  post_install_message:
@@ -62,6 +60,6 @@ rubyforge_project:
62
60
  rubygems_version: 1.3.6
63
61
  signing_key:
64
62
  specification_version: 3
65
- summary: ParseConfig provides simple parsing of standard *nix style config files.
63
+ summary: Config File Parser for Standard Unix/Linux Type Config Files
66
64
  test_files: []
67
65
 
data/README DELETED
@@ -1,57 +0,0 @@
1
- rb-parseconfig
2
- by BJ Dierkes
3
- http://www.5dollarwhitebox.org
4
-
5
- == DESCRIPTION:
6
-
7
- rb-parseconfig is a Ruby class written to parse simple configuration
8
- files in the format of 'param = value'. The key benefit is that your ruby
9
- scripts can use the same configuration files of most unix/linux
10
- applications.
11
-
12
- == FEATURES/PROBLEMS:
13
-
14
- Parsing of simple configuration files (not Ruby specific).
15
- Allows ruby applications as well as Bash Init scripts to use the same config.
16
-
17
- == SYNOPSIS:
18
-
19
- require('rubygems')
20
- require('parseconfig')
21
- config = ParseConfig.new('/path/to/config/file')
22
- puts config['log_file']
23
- puts config['pid_file']
24
- ...
25
-
26
- == REQUIREMENTS:
27
-
28
- * Ruby (Developed on 1.8.6)
29
- * RubyGems
30
-
31
- == INSTALL:
32
-
33
- sudo gem install parseconfig
34
-
35
- == LICENSE:
36
-
37
- The MIT License:
38
-
39
- Copyright (c) 2006 BJ Dierkes
40
-
41
- Permission is hereby granted, free of charge, to any person obtaining a copy
42
- of this software and associated documentation files (the "Software"), to deal
43
- in the Software without restriction, including without limitation the rights
44
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45
- copies of the Software, and to permit persons to whom the Software is
46
- furnished to do so, subject to the following conditions:
47
-
48
- The above copyright notice and this permission notice shall be included in
49
- all copies or substantial portions of the Software.
50
-
51
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57
- THE SOFTWARE.
data/demo.conf DELETED
@@ -1,11 +0,0 @@
1
- admin_email = root@localhost
2
- listen_ip = 127.0.0.1
3
- listen_port = 87345
4
-
5
- [group1]
6
- user_name = johnny
7
- group_name = daemons
8
-
9
- [group2]
10
- user_name = rita
11
- group_name = daemons
data/demo.rb DELETED
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require('rubygems')
4
- require('parseconfig')
5
- #require('./lib/parseconfig.rb')
6
-
7
- begin
8
- c = ParseConfig.new('demo.conf')
9
- rescue Errno::ENOENT
10
- puts "The config file you specified was not found"
11
- exit
12
- rescue Errno::EACCES
13
- puts "The config file you specified is not readable"
14
- exit
15
- end
16
-
17
- puts
18
- puts 'Reading main config section and groups...'
19
- puts '-' * 77
20
- puts
21
- c.write()
22
- puts
23
- puts 'Available params are...'
24
- puts '-' * 77
25
- puts
26
- puts c.get_params()
27
- puts
28
- puts
29
-
30
- puts 'Available sub-groups are...'
31
- puts '-' * 77
32
- puts
33
- puts c.get_groups()
34
- puts
35
- puts
36
-
37
- puts 'Accessing sub-group params...'
38
- puts '-' * 77
39
- puts
40
- puts "group1 user name value is: #{c.params['group1']['user_name']}"
41
- puts
42
- puts
43
-
44
- puts "Using params hash..."
45
- puts '-' * 77
46
- puts
47
- puts "The admin email address is #{c.params['admin_email']}"
48
- puts
49
- puts
50
-
51
- puts "Using get_value (kind of deprecated)..."
52
- puts '-' * 77
53
- puts
54
- puts "The listen address is #{c.get_value('listen_ip')} and the user name " +
55
- "is #{c.get_value('group1')['user_name']}"
56
- puts
57
- puts
58
-
59
- puts "Writing the config out to a file"
60
- puts '-' * 77
61
- puts
62
- f = open('/tmp/parseconfig_sample_config', 'w')
63
- c.write(f)
64
- f.close()
65
- puts "Config written to /tmp/parseconfig_sample_config"
66
- puts