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 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 s']
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.0.0
1
+ 1.1.1
data/lib/iniparse.rb CHANGED
@@ -1,17 +1,13 @@
1
- require 'extlib'
1
+ dir = File.expand_path('iniparse', File.dirname(__FILE__))
2
2
 
3
- dir = Pathname(__FILE__).dirname.expand_path / 'iniparse'
4
-
5
- require dir / 'document'
6
- require dir / 'generator'
7
- require dir / 'line_collection'
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
@@ -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.blank?
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
@@ -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, <<-EOS.compress_lines
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.
@@ -58,7 +58,9 @@ module IniParse
58
58
  #
59
59
  def each(include_blank = false)
60
60
  @lines.each do |line|
61
- yield(line) if include_blank || (! line.blank?)
61
+ if include_blank || ! (line.is_a?(Array) ? line.empty? : line.blank?)
62
+ yield(line)
63
+ end
62
64
  end
63
65
  end
64
66
 
@@ -24,7 +24,7 @@ module IniParse
24
24
  ini = @indent + ini if @indent
25
25
 
26
26
  if has_comment?
27
- ini += ' ' unless ini.blank?
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.blank?
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.blank? ? @comment_sep : super
291
+ @comment !~ /\S/ ? @comment_sep : super
287
292
  end
288
293
  end
289
294
  end # Lines
@@ -1,9 +1,27 @@
1
1
  module IniParse
2
2
  class Parser
3
- cattr_accessor :parse_types
4
- @@parse_types = [ IniParse::Lines::Option,
5
- IniParse::Lines::Section,
6
- IniParse::Lines::Blank ]
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, <<-EOS.compress_lines
48
- A line of your INI document could not be parsed to a LineType:
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 == <<-INI.margin
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 == <<-INI.margin
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
 
@@ -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(Pathname(__FILE__).dirname.expand_path / 'fixtures' / fix)
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.margin
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
- version: 1.0.0
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-01-05 00:00:00 +00:00
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
- type: :runtime
18
- version_requirement:
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
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: rspec
27
- type: :development
28
- version_requirement:
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
- version:
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.5
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.