inih 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6e998b8cdce0816f6f77964b60658041f34e5d23
4
- data.tar.gz: 911f377e3c7e39f772a0bb3700ea70b0f128a789
2
+ SHA256:
3
+ metadata.gz: b34e36b18fe1afa2aa4680a413f1bcfb779d9b0523f9755cbef6814d28539173
4
+ data.tar.gz: 64c99571876f4468350f8a58c99e65b7babbdab21a0ffc074014ed741c20f667
5
5
  SHA512:
6
- metadata.gz: 617ed17dae6e9da378a986b7fc5272c325bd64664b33aabb9c6cbf1ce0151d4332260556586a2d1abcf9a3e1054359f03cc31f527d41034b9c33047f3cb66694
7
- data.tar.gz: 8fb920f32b2baaabe0b3a5d1f87a0736b5bf12f2f06293cf22f19977aba35ddf0169b9b047a6f893899d4498906e84b8b029e5bb58d4485772a1d61f3d21b7e3
6
+ metadata.gz: d693a05a060e2ae66f7a26eee6a36686339acaf22054b55e499cd81b1adba0982bc907237d85085f30fcdd27d703db23e4d36a53add7fe6be6b85d115aa30f0d
7
+ data.tar.gz: 1dcb6104668fd4ddaaecc773f36c2b8d703bc065fbcbb0d0ebea4799e027dd03de03f56bb6da5907cf4a20583c94d95e6767d66574485cb379a72b633257f610
data/README.md CHANGED
@@ -7,7 +7,7 @@ A Ruby wrapper for [inih](https://github.com/benhoyt/inih), a simple INI parser.
7
7
 
8
8
  ### Installation
9
9
 
10
- ```ruby
10
+ ```bash
11
11
  $ gem install inih
12
12
  ```
13
13
 
@@ -35,11 +35,12 @@ INIH.parse "[section]\nkey=value"
35
35
  #=> {"section"=>{"key"=>"value"}}
36
36
  ```
37
37
 
38
- Integers, floating-point numbers, and booleans are coerced into their respective Ruby types.
38
+ Integers, floating-point numbers, and booleans are coerced into their respective Ruby types by
39
+ default, **unless** `normalize: false` is passed to either method.
39
40
 
40
41
  ### TODO
41
42
 
42
- * Coerce scientific-notation?
43
+ * Coerce scientific notation?
43
44
 
44
45
  ### License
45
46
 
@@ -1,33 +1,29 @@
1
1
  #include "inih.h"
2
2
 
3
3
  VALUE mINIH = Qnil;
4
+ VALUE cParseError = Qnil;
4
5
 
5
6
  static int mINIH_ini_handler(void *data, const char *sect, const char *name, const char *val);
6
7
 
7
8
  /*
8
- @overload parse(string)
9
- Parse an INI-formatted string into a Hash.
10
- @param string [String] the INI-formatted string to parse
11
- @return [Hash] the resulting hash
12
- @raise [RuntimeError] if a parse error occurs
9
+ @overload parse_intern(string, normalize)
10
+ @api private
13
11
  */
14
- static VALUE mINIH_parse(VALUE self, VALUE string);
12
+ static VALUE mINIH_parse_intern(VALUE self, VALUE string, VALUE normalize);
15
13
 
16
14
  /*
17
- @overload load(filename)
18
- Parse an INI-formatted file into a Hash.
19
- @param filename [String] the INI-formatted file to parse
20
- @return [Hash] the resulting hash
21
- @raise [RuntimeError] if a parse or I/O error occurs
15
+ @overload load_intern(filename, normalize)
16
+ @api private
22
17
  */
23
- static VALUE mINIH_load(VALUE self, VALUE filename);
18
+ static VALUE mINIH_load_intern(VALUE self, VALUE filename, VALUE normalize);
24
19
 
25
20
  void Init_inih()
26
21
  {
27
22
  mINIH = rb_define_module("INIH");
23
+ cParseError = rb_const_get(mINIH, rb_intern("ParseError"));
28
24
 
29
- rb_define_singleton_method(mINIH, "parse", mINIH_parse, 1);
30
- rb_define_singleton_method(mINIH, "load", mINIH_load, 1);
25
+ rb_define_singleton_method(mINIH, "parse_intern", mINIH_parse_intern, 2);
26
+ rb_define_singleton_method(mINIH, "load_intern", mINIH_load_intern, 2);
31
27
  }
32
28
 
33
29
  static int mINIH_ini_handler(void *data, const char *sect, const char *name, const char *val)
@@ -47,20 +43,25 @@ static int mINIH_ini_handler(void *data, const char *sect, const char *name, con
47
43
  return 1;
48
44
  }
49
45
 
50
- static VALUE mINIH_parse(VALUE self, VALUE string)
46
+ static VALUE mINIH_parse_intern(VALUE self, VALUE string, VALUE normalize)
51
47
  {
52
48
  char *str = StringValueCStr(string);
53
49
  VALUE hash = rb_hash_new();
54
50
  int result;
55
51
 
56
52
  if ((result = ini_parse_string(str, mINIH_ini_handler, &hash)) != 0) {
57
- rb_raise(rb_eRuntimeError, "parse error, line %d", result);
53
+ rb_raise(cParseError, "parse error, line %d", result);
58
54
  }
59
55
 
60
- return rb_funcall(mINIH, rb_intern("normalize"), 1, hash);
56
+ if (normalize) {
57
+ return rb_funcall(mINIH, rb_intern("normalize_hash"), 1, hash);
58
+ }
59
+ else {
60
+ return hash;
61
+ }
61
62
  }
62
63
 
63
- static VALUE mINIH_load(VALUE self, VALUE filename)
64
+ static VALUE mINIH_load_intern(VALUE self, VALUE filename, VALUE normalize)
64
65
  {
65
66
  char *file = StringValueCStr(filename);
66
67
  VALUE hash = rb_hash_new();
@@ -68,12 +69,17 @@ static VALUE mINIH_load(VALUE self, VALUE filename)
68
69
 
69
70
  if ((result = ini_parse(file, mINIH_ini_handler, &hash)) != 0) {
70
71
  if (result < 0) {
71
- rb_raise(rb_eRuntimeError, "I/O error");
72
+ rb_raise(rb_eIOError, "I/O error");
72
73
  }
73
74
  else {
74
- rb_raise(rb_eRuntimeError, "parse error, line %d", result);
75
+ rb_raise(cParseError, "parse error, line %d", result);
75
76
  }
76
77
  }
77
78
 
78
- return rb_funcall(mINIH, rb_intern("normalize"), 1, hash);
79
+ if (normalize) {
80
+ return rb_funcall(mINIH, rb_intern("normalize_hash"), 1, hash);
81
+ }
82
+ else {
83
+ return hash;
84
+ }
79
85
  }
@@ -1,15 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "inih/exceptions"
3
4
  require_relative "ext/inih"
4
5
 
5
6
  # The primary namespace for {INIH}.
6
7
  module INIH
8
+ module_function
9
+
7
10
  # The current version of ruby-inih.
8
- VERSION = "1.1.1"
11
+ VERSION = "2.0.0"
12
+
13
+ # Parse an INI-formatted string into a Hash.
14
+ # @param string [String] the INI-formatted string to parse
15
+ # @param normalize [Boolean] whether or not to normalize the types of parsed values
16
+ # @return [Hash] the parsed hash
17
+ # @raise [INIH::ParseError] if a parse error occurs
18
+ def parse(string, normalize: true)
19
+ parse_intern string, normalize
20
+ end
21
+
22
+ # Parse an INI-formatted file into a Hash.
23
+ # @param filename [String] the INI-formatted file to parse
24
+ # @param normalize [Boolean] whether or not to normalize the types of parsed values
25
+ # @return [Hash] the resulting hash
26
+ # @raise [INIH::ParseError] if a parse error occurs
27
+ # @raise [IOError] if an I/O error occurs
28
+ def load(filename, normalize: true)
29
+ load_intern filename, normalize
30
+ end
9
31
 
10
32
  # Normalize a parsed INI file's values.
11
33
  # @api private
12
- def self.normalize(hsh)
34
+ def normalize_hash(hsh)
13
35
  hsh.map do |k, sect|
14
36
  [k, normalize_sect(sect)]
15
37
  end.to_h
@@ -17,7 +39,7 @@ module INIH
17
39
 
18
40
  # Normalize the values in a section of a parsed INI file.
19
41
  # @api private
20
- def self.normalize_sect(sect)
42
+ def normalize_sect(sect)
21
43
  sect.map do |k, v|
22
44
  nv = case v
23
45
  when "" then nil
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module INIH
4
+ # A generic error in {INIH}.
5
+ class INIHError < RuntimeError
6
+ end
7
+
8
+ # Raised whenever parsing fails.
9
+ class ParseError < INIHError
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007-2018 Loren Segal
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inih
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2018-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description: A native library for parsing INI files.
14
42
  email: william@tuffbizz.com
15
43
  executables: []
@@ -27,6 +55,8 @@ files:
27
55
  - ext/inih/inih.c
28
56
  - ext/inih/inih.h
29
57
  - lib/inih.rb
58
+ - lib/inih/exceptions.rb
59
+ - vendor/bundle/gems/yard-0.9.14/LICENSE
30
60
  homepage: https://github.com/woodruffw/ruby-inih
31
61
  licenses:
32
62
  - MIT
@@ -47,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
77
  version: '0'
48
78
  requirements: []
49
79
  rubyforge_project:
50
- rubygems_version: 2.6.14
80
+ rubygems_version: 2.7.6
51
81
  signing_key:
52
82
  specification_version: 4
53
83
  summary: inih - a Ruby wrapper for a simple C INI parser