parseconfig 0.4.1 → 0.4.2

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.
Files changed (5) hide show
  1. data/Changelog +22 -16
  2. data/demo.conf +1 -0
  3. data/demo.rb +2 -2
  4. data/lib/parseconfig.rb +30 -28
  5. metadata +40 -33
data/Changelog CHANGED
@@ -1,33 +1,39 @@
1
- * Sun Sep 03 2007 BJ Dierkes <wdierkes@5dollarwhitebox.org> - 0.4.1
1
+ Thu Feb 28, 2008 - v0.4.2
2
+ - Fixed bug where if the value contains a '=' then the parameter
3
+ is not properly set. [bjd]
4
+ - Fixed bug #13680 Unable to parse config options that contain
5
+ single quotes. [bjd]
6
+
7
+ Sun Sep 03, 2007 - v0.4.1
2
8
  - Now using 'instance_variable_set' and 'instance_variable_get'
3
- instead of 'eval' (yeah.. that was dirty).
9
+ instead of 'eval' (yeah.. that was dirty). [bjd]
4
10
 
5
11
 
6
- * Sat Aug 11 2007 BJ Dierkes <wdierkes@5dollarwhitebox.org> - 0.3.2
7
- - reorganizing files a bit
8
- - renamed methods .... no more uglyStyle... now new_style.
12
+ Sat Aug 11, 2007 - v0.3.2
13
+ - reorganizing files a bit. [bjd]
14
+ - renamed methods .... no more uglyStyle... now new_style. [bjd]
9
15
 
10
16
 
11
- * Fri Feb 23 2007 BJ Dierkes <wdierkes@5dollarwhitebox.org> - 0.3.1
17
+ Fri Feb 23, 2007 - v0.3.1
12
18
  - Added a bit of code to remove 'single' quotes... so, until I figure
13
- a better option, values can't contain single quotes
19
+ a better option, values can't contain single quotes. [bjd]
14
20
 
15
21
 
16
- * Wed Feb 07 2007 BJ Dierkes <wdierkes@5dollarwhitebox.org> - 0.2.1
17
- - Renamed ParseConfig.class.rb to ParseConfig.rb
18
- - Add 'strip' to remove trailing white spaces from config file
22
+ Wed Feb 07, 2007 - v0.2.1
23
+ - Renamed ParseConfig.class.rb to ParseConfig.rb. [bjd]
24
+ - Add 'strip' to remove trailing white spaces from config file. [bjd]
19
25
 
20
26
 
21
- * Wed Dec 13 2006 BJ Dierkes <wdierkes@5dollarwhitebox.org> - 0.1.3
22
- - Added error check to ensure configFile is readable
27
+ Wed Dec 13, 2006 - v0.1.3
28
+ - Added error check to ensure configFile is readable. [bjd]
23
29
 
24
30
 
25
- * Sat Nov 25 2006 BJ Dierkes <wdierkes@5dollarwhitebox.org> - 0.1.2
31
+ Sat Nov 25, 2006 - v0.1.2
26
32
  - Added regex to only read lines matching /\s*=\s*/ as
27
- The class would bork if you had say, and empty line
33
+ The class would bork if you had say, and empty line. [bjd]
28
34
 
29
35
 
30
- * Fri Nov 24 2006 BJ Dierkes <wdierkes@5dollarwhitebox.org> - 0.1.1
31
- - Built class, which is functional and fully usable
36
+ Fri Nov 24 2006 - v0.1.1
37
+ - Built class, which is functional and fully usable. [bjd]
32
38
 
33
39
 
data/demo.conf CHANGED
@@ -2,3 +2,4 @@
2
2
  name = johnny
3
3
  age = 21
4
4
  address = '5555 North South 77th street'
5
+ slogan = "I ain't no fool"
data/demo.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require('rubygems')
4
4
  require('parseconfig')
5
- #require('./lib/parse_config.rb')
5
+ #require('./lib/parseconfig.rb')
6
6
 
7
7
  begin
8
8
  myConfig = ParseConfig.new('demo.conf')
@@ -16,5 +16,5 @@ end
16
16
 
17
17
  puts "Hello, my name is #{myConfig.get_value('name')}."
18
18
  puts "I am #{myConfig.get_value('age')} years old, but will be #{myConfig.override_value('age', '22')} soon."
19
- puts "I currently live at #{myConfig.get_value('address')}."
19
+ puts "I currently live at #{myConfig.get_value('address')}, and my slogan is \"#{myConfig.get_value('slogan')}\"."
20
20
 
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # $Id: parseconfig.rb 34 2007-09-04 01:06:46Z wdierkes $
2
+ # $Id: parseconfig.rb 36 2008-02-29 07:26:31Z wdierkes $
3
3
  #
4
- # Author:: BJ Dierkes <wdierkes@5dollarwhitebox.org>
5
- # Copyright:: Copyright (c) 2006,2007 5dollarwhitebox.org
6
- # License:: GPL
7
- # URL:: http://www.5dollarwhitebox.org
4
+ # Author:: BJ Dierkes <wdierkes@5dollarwhitebox.org>
5
+ # Copyright:: Copyright (c) 2006,2007 5dollarwhitebox.org
6
+ # License:: GPL
7
+ # URL:: http://www.5dollarwhitebox.org
8
8
  #
9
9
 
10
10
  # This class was written to simplify the parsing of configuration
@@ -17,14 +17,14 @@
17
17
 
18
18
  class ParseConfig
19
19
 
20
- Version = '0.4.1'
20
+ Version = '0.4.2'
21
21
 
22
- # Initialize the class with the path to the 'config_file'
23
- # The class objects are dynamically generated by the
24
- # name of the 'param' in the config file. Therefore, if
25
- # the config file is 'param = value' then the itializer
26
- # will eval "@param = value"
27
- #
22
+ # Initialize the class with the path to the 'config_file'
23
+ # The class objects are dynamically generated by the
24
+ # name of the 'param' in the config file. Therefore, if
25
+ # the config file is 'param = value' then the itializer
26
+ # will eval "@param = value"
27
+ #
28
28
  def initialize(config_file)
29
29
  @config_file = config_file
30
30
  raise Errno::EACCES, "#{self.config_file} is not readable" unless File.readable?(self.config_file)
@@ -32,13 +32,15 @@ class ParseConfig
32
32
  line.chomp
33
33
  unless (/^\#/.match(line))
34
34
  if(/\s*=\s*/.match(line))
35
- param, value = line.split(/\s*=\s*/)
35
+ param, value = line.split(/\s*=\s*/, 2)
36
36
  var_name = "#{param}".chomp.strip
37
37
  value = value.chomp.strip
38
38
  new_value = ''
39
39
  if (value)
40
- value.each_byte do |byte|
41
- new_value << byte.chr unless (byte.chr == "\'")
40
+ if value =~ /^['"](.*)['"]$/
41
+ new_value = $1
42
+ else
43
+ new_value = value
42
44
  end
43
45
  else
44
46
  new_value = ''
@@ -49,27 +51,27 @@ class ParseConfig
49
51
  }
50
52
  end
51
53
 
52
- # This method will provide the value held by the object "@param"
53
- # where "@param" is actually the name of the param in the config
54
- # file.
54
+ # This method will provide the value held by the object "@param"
55
+ # where "@param" is actually the name of the param in the config
56
+ # file.
55
57
  def get_value(param)
56
58
  self.instance_variable_get("@#{param}")
57
59
  end
58
60
 
59
- # This method is simple. Should you need to override a value
60
- # dynamically, use override_value(param, value) where 'param' is
61
- # the name of the paramater in the config file.
62
- #
63
- def override_value(param, value)
64
- self.instance_variable_set("@#{param}", value)
65
- end
61
+ # This method is simple. Should you need to override a value
62
+ # dynamically, use override_value(param, value) where 'param' is
63
+ # the name of the paramater in the config file.
64
+ #
65
+ def override_value(param, value)
66
+ self.instance_variable_set("@#{param}", value)
67
+ end
66
68
 
67
- # This method will set the value of '@param' to nil (not in the config
68
- # file, only in the app).
69
+ # This method will set the value of '@param' to nil (not in the config
70
+ # file, only in the app).
69
71
  def nil_value(param)
70
72
  self.instance_variable_set("@#{param}", nil)
71
73
  end
72
-
74
+
73
75
  def config_file=(config_file)
74
76
  @config_file = config_file
75
77
  end
metadata CHANGED
@@ -1,33 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: parseconfig
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.1
7
- date: 2007-09-03 00:00:00 -05:00
8
- summary: ParseConfig provides simple parsing of standard *nix style config files.
9
- require_paths:
10
- - lib
11
- email: wdierkes@5dollarwhitebox.org
12
- homepage: http://www.5dollarwhitebox.org/
13
- rubyforge_project:
14
- description: ParseConfig provides simple parsing of standard *nix style config files.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.4.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - BJ Dierkes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-28 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ParseConfig provides simple parsing of standard *nix style config files.
17
+ email: wdierkes@5dollarwhitebox.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
25
  - README
33
26
  - Changelog
@@ -36,17 +29,31 @@ files:
36
29
  - demo.rb
37
30
  - demo.conf
38
31
  - lib/parseconfig.rb
39
- test_files: []
40
-
32
+ has_rdoc: false
33
+ homepage: http://www.5dollarwhitebox.org/
34
+ post_install_message:
41
35
  rdoc_options: []
42
36
 
43
- extra_rdoc_files: []
44
-
45
- executables: []
46
-
47
- extensions: []
48
-
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
49
51
  requirements: []
50
52
 
51
- dependencies: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.0.1
55
+ signing_key:
56
+ specification_version: 2
57
+ summary: ParseConfig provides simple parsing of standard *nix style config files.
58
+ test_files: []
52
59