parseconfig 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Changelog +4 -0
  2. data/demo.conf +1 -0
  3. data/demo.rb +16 -4
  4. data/lib/parseconfig.rb +15 -12
  5. metadata +2 -2
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ Sat Mar 28, 2009 - v0.4.3
2
+ - Added the self.params member that is a Hash holding all parameter/values.
3
+ - Added the 'get_params' to return an array of all config parameters.
4
+
1
5
  Thu Feb 28, 2008 - v0.4.2
2
6
  - Fixed bug where if the value contains a '=' then the parameter
3
7
  is not properly set. [bjd]
data/demo.conf CHANGED
@@ -1,5 +1,6 @@
1
1
  # Sample configuration file to demo ParseConfig
2
2
  name = johnny
3
3
  age = 21
4
+ # checking bug 23244
4
5
  address = '5555 North South 77th street'
5
6
  slogan = "I ain't no fool"
data/demo.rb CHANGED
@@ -5,7 +5,7 @@ require('parseconfig')
5
5
  #require('./lib/parseconfig.rb')
6
6
 
7
7
  begin
8
- myConfig = ParseConfig.new('demo.conf')
8
+ c = ParseConfig.new('demo.conf')
9
9
  rescue Errno::ENOENT
10
10
  puts "The config file you specified was not found"
11
11
  exit
@@ -14,7 +14,19 @@ rescue Errno::EACCES
14
14
  exit
15
15
  end
16
16
 
17
- puts "Hello, my name is #{myConfig.get_value('name')}."
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')}, and my slogan is \"#{myConfig.get_value('slogan')}\"."
17
+ puts "Hello, my name is #{c.get_value('name')}."
18
+ puts "I am #{c.get_value('age')} years old, but will be #{c.override_value('age', '22')} soon."
19
+ puts "I currently live at #{c.params['address']}, and my slogan is \"#{c.get_value('slogan')}\"."
20
20
 
21
+ puts
22
+ puts
23
+ puts "All the paramaters are..."
24
+ res = c.get_params()
25
+ res.each do |param|
26
+ puts param
27
+ end
28
+
29
+ puts
30
+ puts
31
+ puts "using params hash"
32
+ puts c.params['age']
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # $Id: parseconfig.rb 36 2008-02-29 07:26:31Z wdierkes $
2
+ # $Id: parseconfig.rb 37 2008-02-29 07:27:33Z wdierkes $
3
3
  #
4
4
  # Author:: BJ Dierkes <wdierkes@5dollarwhitebox.org>
5
5
  # Copyright:: Copyright (c) 2006,2007 5dollarwhitebox.org
@@ -17,7 +17,9 @@
17
17
 
18
18
  class ParseConfig
19
19
 
20
- Version = '0.4.2'
20
+ Version = '0.4.3'
21
+
22
+ attr_accessor :config_file, :params
21
23
 
22
24
  # Initialize the class with the path to the 'config_file'
23
25
  # The class objects are dynamically generated by the
@@ -27,9 +29,13 @@ class ParseConfig
27
29
  #
28
30
  def initialize(config_file)
29
31
  @config_file = config_file
30
- raise Errno::EACCES, "#{self.config_file} is not readable" unless File.readable?(self.config_file)
32
+ @params = {}
33
+ if !File.readable?(self.config_file)
34
+ raise Errno::EACCES, "#{self.config_file} is not readable"
35
+ end
36
+
31
37
  open(self.config_file).each { |line|
32
- line.chomp
38
+ line.strip!
33
39
  unless (/^\#/.match(line))
34
40
  if(/\s*=\s*/.match(line))
35
41
  param, value = line.split(/\s*=\s*/, 2)
@@ -46,6 +52,7 @@ class ParseConfig
46
52
  new_value = ''
47
53
  end
48
54
  self.instance_variable_set("@#{var_name}", new_value)
55
+ self.params["#{var_name}"] = new_value
49
56
  end
50
57
  end
51
58
  }
@@ -71,13 +78,9 @@ class ParseConfig
71
78
  def nil_value(param)
72
79
  self.instance_variable_set("@#{param}", nil)
73
80
  end
74
-
75
- def config_file=(config_file)
76
- @config_file = config_file
77
- end
78
-
79
- def config_file()
80
- @config_file
81
+
82
+ def get_params()
83
+ return self.params.keys
81
84
  end
82
-
85
+
83
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parseconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Dierkes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-28 00:00:00 -06:00
12
+ date: 2009-03-28 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15