parseconfig 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +4 -0
  3. data/LICENSE +1 -1
  4. data/README.md +19 -18
  5. data/lib/parseconfig.rb +22 -8
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d1e9b35305ee60ce0732906eee17091e8c3564e
4
- data.tar.gz: 20c5c7343345170d04a5f9009f55f9a31bf61cc2
3
+ metadata.gz: e211188d856835d945577417f00876882067caa2
4
+ data.tar.gz: 8004e0a522105456dde4bf1d35c0c6ac0c4c1bce
5
5
  SHA512:
6
- metadata.gz: 7db0455728e0e7a4cbb058db4766e28bf5029258b10f808c11bf5eca06a5d53dafb9499dac1339bbcf847306ac3f39c6f55cd9ed77dfbdb57134170dcd3ff413
7
- data.tar.gz: 31d19e90674de0732c023e644b90e9860c5845b8d0cabed89022786b45d8c43a4d16c81cd8b2f9f196da6548ada8a95741ee941fbe43bf1b250a5e822373a9c3
6
+ metadata.gz: 98046197998f9eca8c26805de80a7362776a56b9172312a71d3d8963e3eb9dbfc627248180ab847476e9a7d009a8dff32b3cefa2d787d891b8cc569322fa6c14
7
+ data.tar.gz: ba8a718dfd8a99c6ee194b97f1be7d92cb562a49a4fcab0752c320d0605325244f3c002777762bfc8fd1f642a6ea1c78dd496a24f8d77ec0b64d6c7739d97d84
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ Mon Jan 25, 2016 - v1.0.7
2
+ - Support alternative comment types (default: ['#', ';']) (@voobscout)
3
+ Resolves Issue #30
4
+
1
5
  Mon Oct 06, 2014 - v1.0.6
2
6
  - Fix where extraneous double quotes were getting wrapped around parameters
3
7
  that have non-word characters (issue #19)
data/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  The MIT License:
3
3
 
4
- Copyright (c) 2006-2014 Data Folk Labs, LLC
4
+ Copyright (c) 2006-2016 Data Folk Labs, LLC
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Ruby ParseConfig Library
2
- ========================
1
+ # Ruby ParseConfig Library
3
2
 
4
3
  ParseConfig provides simple parsing of standard configuration files in the
5
4
  form of 'param = value'. It also supports nested [group] sections.
@@ -9,34 +8,37 @@ form of 'param = value'. It also supports nested [group] sections.
9
8
  Installation
10
9
  ------------
11
10
 
12
- $ sudo gem install parseconfig
11
+ ```
12
+ $ sudo gem install parseconfig
13
+ ```
13
14
 
14
15
  Gemfile
15
16
 
16
- gem 'parseconfig'
17
+ ```
18
+ gem 'parseconfig'
19
+ ```
17
20
 
18
- Usage
19
- -----
21
+ ## Usage
20
22
 
21
23
  An example configuration file might look like:
22
24
 
23
- # Example Config
24
- param1 = value1
25
- param2 = value2
25
+ ```
26
+ # Example Config
27
+ param1 = value1
28
+ param2 = value2
26
29
 
27
- [group1]
28
- group1_param1 = group1_value1
29
- group1_param2 = group1_value2
30
+ [group1]
31
+ group1_param1 = group1_value1
32
+ group1_param2 = group1_value2
30
33
 
31
- [group2]
32
- group2_param1 = group2_value1
33
- group2_param2 = group2_value2
34
+ [group2]
35
+ group2_param1 = group2_value1
36
+ group2_param2 = group2_value2
34
37
 
35
38
 
36
39
  Access it with ParseConfig:
37
40
 
38
41
  ```ruby
39
-
40
42
  >> require 'parseconfig'
41
43
  => true
42
44
 
@@ -81,8 +83,7 @@ Access it with ParseConfig:
81
83
 
82
84
  ```
83
85
 
84
- License
85
- -------
86
+ ## License
86
87
 
87
88
  The ParseConfig library is Open Source and distributed under the MIT license.
88
89
  Please see the LICENSE file included with this software.
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: BJ Dierkes <derks@datafolklabs.com>
3
- # Copyright:: Copyright (c) 2006,2013 BJ Dierkes
3
+ # Copyright:: Copyright (c) 2006,2016 Data Folk Labs, LLC
4
4
  # License:: MIT
5
5
  # URL:: https://github.com/datafolklabs/ruby-parseconfig
6
6
  #
@@ -18,7 +18,7 @@
18
18
 
19
19
  class ParseConfig
20
20
 
21
- Version = '1.0.6'
21
+ Version = '1.0.7'
22
22
 
23
23
  attr_accessor :config_file, :params, :groups
24
24
 
@@ -28,10 +28,12 @@ class ParseConfig
28
28
  # the config file is 'param = value' then the itializer
29
29
  # will eval "@param = value"
30
30
  #
31
- def initialize(config_file=nil)
31
+ def initialize(config_file=nil, separator='=', comments: ['#', ';'])
32
32
  @config_file = config_file
33
33
  @params = {}
34
34
  @groups = []
35
+ @splitRegex = '\s*' + separator + '\s*'
36
+ @comments = comments
35
37
 
36
38
  if(self.config_file)
37
39
  self.validate_config()
@@ -64,9 +66,17 @@ class ParseConfig
64
66
  rescue NoMethodError
65
67
  end
66
68
 
67
- unless (/^\#/.match(line))
68
- if(/\s*=\s*/.match(line))
69
- param, value = line.split(/\s*=\s*/, 2)
69
+ is_comment = false
70
+ @comments.each do |comment|
71
+ if (/^#{comment}/.match(line))
72
+ is_comment = true
73
+ break
74
+ end
75
+ end
76
+
77
+ unless is_comment
78
+ if(/#{@splitRegex}/.match(line))
79
+ param, value = line.split(/#{@splitRegex}/, 2)
70
80
  var_name = "#{param}".chomp.strip
71
81
  value = value.chomp.strip
72
82
  new_value = ''
@@ -124,11 +134,15 @@ class ParseConfig
124
134
 
125
135
  # This method adds an element to the config object (not the config file)
126
136
  # By adding a Hash, you create a new group
127
- def add(param_name, value)
137
+ def add(param_name, value, override = false)
128
138
  if value.class == Hash
129
139
  if self.params.has_key?(param_name)
130
140
  if self.params[param_name].class == Hash
131
- self.params[param_name].merge!(value)
141
+ if override
142
+ self.params[param_name] = value
143
+ else
144
+ self.params[param_name].merge!(value)
145
+ end
132
146
  elsif self.params.has_key?(param_name)
133
147
  if self.params[param_name].class != value.class
134
148
  raise ArgumentError, "#{param_name} already exists, and is of different type!"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parseconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Dierkes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-06 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ParseConfig provides simple parsing of standard configuration files in
14
14
  the form of 'param = value'. It also supports nested [group] sections.
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  version: '0'
41
41
  requirements: []
42
42
  rubyforge_project:
43
- rubygems_version: 2.2.2
43
+ rubygems_version: 2.4.1
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: Config File Parser for Standard Unix/Linux Type Config Files