iniparse 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/iniparse.rb +7 -11
- data/lib/iniparse/document.rb +1 -1
- data/lib/iniparse/generator.rb +3 -4
- data/lib/iniparse/line_collection.rb +3 -1
- data/lib/iniparse/lines.rb +8 -3
- data/lib/iniparse/parser.rb +25 -8
- data/spec/lines_spec.rb +10 -12
- data/spec/spec_fixtures.rb +9 -7
- metadata +28 -13
data/Rakefile
CHANGED
@@ -60,7 +60,7 @@ desc "Run all examples"
|
|
60
60
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
61
61
|
spec.libs << 'lib' << 'spec'
|
62
62
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
63
|
-
spec.spec_opts = ['-c -f
|
63
|
+
spec.spec_opts = ['-c -f p']
|
64
64
|
end
|
65
65
|
|
66
66
|
desc "Run all examples with RCov"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
data/lib/iniparse.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
|
1
|
+
dir = File.expand_path('iniparse', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require dir
|
6
|
-
require dir
|
7
|
-
require dir
|
8
|
-
require dir / 'lines'
|
9
|
-
require dir / 'parser'
|
3
|
+
require File.join(dir, 'document')
|
4
|
+
require File.join(dir, 'generator')
|
5
|
+
require File.join(dir, 'line_collection')
|
6
|
+
require File.join(dir, 'lines')
|
7
|
+
require File.join(dir, 'parser')
|
10
8
|
|
11
9
|
module IniParse
|
12
|
-
VERSION = File.read(
|
13
|
-
Pathname(__FILE__).dirname.expand_path / '..' / 'VERSION'
|
14
|
-
).strip
|
10
|
+
VERSION = File.read('VERSION').strip
|
15
11
|
|
16
12
|
# A base class for IniParse errors.
|
17
13
|
class IniParseError < StandardError; end
|
data/lib/iniparse/document.rb
CHANGED
@@ -57,7 +57,7 @@ module IniParse
|
|
57
57
|
#
|
58
58
|
def save(path = nil)
|
59
59
|
@path = path if path
|
60
|
-
raise IniParseError, 'No path given to Document#save' if @path
|
60
|
+
raise IniParseError, 'No path given to Document#save' if @path !~ /\S/
|
61
61
|
File.open(@path, 'w') { |f| f.write(self.to_ini) }
|
62
62
|
end
|
63
63
|
end
|
data/lib/iniparse/generator.rb
CHANGED
@@ -145,10 +145,9 @@ module IniParse
|
|
145
145
|
)
|
146
146
|
rescue LineNotAllowed
|
147
147
|
# Tried to add an Option to a Document.
|
148
|
-
raise NoSectionError,
|
149
|
-
Your INI document contains an option before the first section is
|
150
|
-
declared which is not allowed.
|
151
|
-
EOS
|
148
|
+
raise NoSectionError,
|
149
|
+
'Your INI document contains an option before the first section is ' \
|
150
|
+
'declared which is not allowed.'
|
152
151
|
end
|
153
152
|
|
154
153
|
# Adds a new comment line to the document.
|
data/lib/iniparse/lines.rb
CHANGED
@@ -24,7 +24,7 @@ module IniParse
|
|
24
24
|
ini = @indent + ini if @indent
|
25
25
|
|
26
26
|
if has_comment?
|
27
|
-
ini += ' '
|
27
|
+
ini += ' ' if ini =~ /\S/ # not blank
|
28
28
|
ini = ini.ljust(@comment_offset)
|
29
29
|
ini += comment
|
30
30
|
end
|
@@ -42,6 +42,11 @@ module IniParse
|
|
42
42
|
def comment
|
43
43
|
'%s %s' % [@comment_sep, @comment]
|
44
44
|
end
|
45
|
+
|
46
|
+
# Returns whether this is a line which has no data.
|
47
|
+
def blank?
|
48
|
+
false
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
# Represents a section header in an INI document. Section headers consist
|
@@ -249,7 +254,7 @@ module IniParse
|
|
249
254
|
end
|
250
255
|
|
251
256
|
def self.parse(line, opts)
|
252
|
-
if line
|
257
|
+
if line !~ /\S/ # blank
|
253
258
|
if opts[:comment].nil?
|
254
259
|
[:blank]
|
255
260
|
else
|
@@ -283,7 +288,7 @@ module IniParse
|
|
283
288
|
# but without a comment, just the seperator will be returned.
|
284
289
|
#
|
285
290
|
def comment
|
286
|
-
@comment
|
291
|
+
@comment !~ /\S/ ? @comment_sep : super
|
287
292
|
end
|
288
293
|
end
|
289
294
|
end # Lines
|
data/lib/iniparse/parser.rb
CHANGED
@@ -1,9 +1,27 @@
|
|
1
1
|
module IniParse
|
2
2
|
class Parser
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
|
4
|
+
# Returns the line types.
|
5
|
+
#
|
6
|
+
# ==== Returns
|
7
|
+
# Array
|
8
|
+
#
|
9
|
+
def self.parse_types
|
10
|
+
@@parse_types ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sets the line types. Handy if you want to add your own custom Line
|
14
|
+
# classes.
|
15
|
+
#
|
16
|
+
# ==== Parameters
|
17
|
+
# types<Array[IniParse::Lines::Line]>:: An array containing Line classes.
|
18
|
+
#
|
19
|
+
def self.parse_types=(types)
|
20
|
+
parse_types.replace(types)
|
21
|
+
end
|
22
|
+
|
23
|
+
self.parse_types = [ IniParse::Lines::Option,
|
24
|
+
IniParse::Lines::Section, IniParse::Lines::Blank ]
|
7
25
|
|
8
26
|
# Creates a new Parser instance for parsing string +source+.
|
9
27
|
#
|
@@ -44,10 +62,9 @@ module IniParse
|
|
44
62
|
end
|
45
63
|
|
46
64
|
if parsed.nil?
|
47
|
-
raise IniParse::ParseError,
|
48
|
-
A line of your INI document could not be parsed to a
|
49
|
-
'#{line}'.
|
50
|
-
EOS
|
65
|
+
raise IniParse::ParseError,
|
66
|
+
"A line of your INI document could not be parsed to a " \
|
67
|
+
"LineType: '#{line}'."
|
51
68
|
end
|
52
69
|
|
53
70
|
parsed
|
data/spec/lines_spec.rb
CHANGED
@@ -250,24 +250,22 @@ describe 'IniParse::Lines::Section' do
|
|
250
250
|
)
|
251
251
|
@section.lines << IniParse::Lines::Option.new('b', 'val2')
|
252
252
|
|
253
|
-
@section.to_ini.should ==
|
254
|
-
[a section]
|
255
|
-
a = val1
|
256
|
-
|
257
|
-
; my comment
|
258
|
-
b = val2
|
259
|
-
INI
|
253
|
+
@section.to_ini.should ==
|
254
|
+
"[a section]\n" \
|
255
|
+
"a = val1\n" \
|
256
|
+
"\n" \
|
257
|
+
"; my comment\n" \
|
258
|
+
"b = val2"
|
260
259
|
end
|
261
260
|
|
262
261
|
it 'should include duplicate lines' do
|
263
262
|
@section.lines << IniParse::Lines::Option.new('a', 'val1')
|
264
263
|
@section.lines << IniParse::Lines::Option.new('a', 'val2')
|
265
264
|
|
266
|
-
@section.to_ini.should ==
|
267
|
-
[a section]
|
268
|
-
a = val1
|
269
|
-
a = val2
|
270
|
-
INI
|
265
|
+
@section.to_ini.should ==
|
266
|
+
"[a section]\n" \
|
267
|
+
"a = val1\n" \
|
268
|
+
"a = val2"
|
271
269
|
end
|
272
270
|
end
|
273
271
|
|
data/spec/spec_fixtures.rb
CHANGED
@@ -7,40 +7,42 @@ module IniParse
|
|
7
7
|
if @@fixtures.has_key?(fix)
|
8
8
|
@@fixtures[fix]
|
9
9
|
else
|
10
|
-
@@fixtures[fix] = File.read(
|
10
|
+
@@fixtures[fix] = File.read(
|
11
|
+
File.join(File.expand_path('fixtures', File.dirname(__FILE__)), fix)
|
12
|
+
)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
def self.[]=(fix, val)
|
15
|
-
@@fixtures[fix] = val
|
17
|
+
@@fixtures[fix] = val
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
IniParse::Test::Fixtures[:comment_before_section] = <<-FIX
|
23
|
+
IniParse::Test::Fixtures[:comment_before_section] = <<-FIX.gsub(/^ /, '')
|
22
24
|
; This is a comment
|
23
25
|
[first_section]
|
24
26
|
key = value
|
25
27
|
FIX
|
26
28
|
|
27
|
-
IniParse::Test::Fixtures[:blank_before_section] = <<-FIX
|
29
|
+
IniParse::Test::Fixtures[:blank_before_section] = <<-FIX.gsub(/^ /, '')
|
28
30
|
|
29
31
|
[first_section]
|
30
32
|
key = value
|
31
33
|
FIX
|
32
34
|
|
33
|
-
IniParse::Test::Fixtures[:blank_in_section] = <<-FIX
|
35
|
+
IniParse::Test::Fixtures[:blank_in_section] = <<-FIX.gsub(/^ /, '')
|
34
36
|
[first_section]
|
35
37
|
|
36
38
|
key = value
|
37
39
|
FIX
|
38
40
|
|
39
|
-
IniParse::Test::Fixtures[:option_before_section] = <<-FIX
|
41
|
+
IniParse::Test::Fixtures[:option_before_section] = <<-FIX.gsub(/^ /, '')
|
40
42
|
key = value
|
41
43
|
[first_section]
|
42
44
|
FIX
|
43
45
|
|
44
|
-
IniParse::Test::Fixtures[:invalid_line] = <<-FIX
|
46
|
+
IniParse::Test::Fixtures[:invalid_line] = <<-FIX.gsub(/^ /, '')
|
45
47
|
this line is not valid
|
46
48
|
FIX
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iniparse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Anthony Williams
|
@@ -9,29 +14,37 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-02-23 00:00:00 +00:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: extlib
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
- 9
|
23
31
|
version: 0.9.9
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: rspec
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 2
|
44
|
+
- 0
|
33
45
|
version: 1.2.0
|
34
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
35
48
|
description: A pure Ruby library for parsing INI documents.
|
36
49
|
email: anthony@ninecraft.com
|
37
50
|
executables: []
|
@@ -82,18 +95,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
95
|
requirements:
|
83
96
|
- - ">="
|
84
97
|
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
85
100
|
version: "0"
|
86
|
-
version:
|
87
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
102
|
requirements:
|
89
103
|
- - ">="
|
90
104
|
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
91
107
|
version: "0"
|
92
|
-
version:
|
93
108
|
requirements: []
|
94
109
|
|
95
110
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.3.
|
111
|
+
rubygems_version: 1.3.6
|
97
112
|
signing_key:
|
98
113
|
specification_version: 3
|
99
114
|
summary: A pure Ruby library for parsing INI documents.
|