inih 0.1.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +29 -2
- data/README.md +6 -4
- data/ext/inih/inih.c +27 -21
- data/lib/inih.rb +27 -7
- data/lib/inih/exceptions.rb +11 -0
- data/lib/inih/version.rb +6 -0
- data/vendor/bundle/gems/yard-0.9.19/LICENSE +22 -0
- metadata +63 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b0dc6ee69dd1c743a8b266c03e3f09242b22883b08524f0957aac889b5c108d8
|
4
|
+
data.tar.gz: 0db810c2b58a7d971d4b6bbbbed1b5e0cd7dd1f13fd393040553ac1a63ecd3a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10080d9a19918482e5abe6389c6f3b2bca99045ef2af42bfdd1ef13d0983cae47a6c68d885fda3b123fa02cb75d4cae918ea5396d502c0a9c878be1c9c29e55c
|
7
|
+
data.tar.gz: 189eb5996dd71b2027d99eaf47bfeb5f93ac4d3ace591232adf2529725b11e20cfb10749376f0421fbf5d214a2b8826395bc375c851b96367a86ae50f4470f8f
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
The MIT License (MIT)
|
1
|
+
The MIT License (MIT) with restrictions
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2020 William Woodruff <william @ yossarian.net>
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -19,3 +19,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
THE SOFTWARE.
|
22
|
+
|
23
|
+
The following terms additionally apply and override any above terms for
|
24
|
+
applicable parties:
|
25
|
+
|
26
|
+
You may not use, copy, modify, merge, publish, distribute, sublicense,
|
27
|
+
and/or sell copies of the Software in a military or law enforcement context,
|
28
|
+
defined as follows:
|
29
|
+
|
30
|
+
1. A military context is a professional context where the intended application
|
31
|
+
of the Software is integration or use with or by military software, tools
|
32
|
+
(software or hardware), or personnel. This includes contractors and
|
33
|
+
subcontractors as well as research affiliates of any military organization.
|
34
|
+
|
35
|
+
2. A law enforcement context is a professional context where the intended
|
36
|
+
application of the Software is integration or use with or by law enforcement
|
37
|
+
software, tools (software or hardware), or personnel. This includes
|
38
|
+
contractors and subcontractors as well as research affiliates of any law
|
39
|
+
enforcement organization.
|
40
|
+
|
41
|
+
Entities that sell or license to military or law enforcement organizations
|
42
|
+
may use the Software under the original terms, but only in contexts that do
|
43
|
+
not assist or supplement the sold or licensed product.
|
44
|
+
|
45
|
+
Students and academics who are affiliated with research institutions may use
|
46
|
+
the Software under the original terms, but only in contexts that do not assist
|
47
|
+
or supplement collaboration or affiliation with any military or law
|
48
|
+
enforcement organization.
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
ruby-inih
|
2
2
|
=========
|
3
3
|
|
4
|
+
![license](https://raster.shields.io/badge/license-MIT%20with%20restrictions-green.png)
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/inih.svg)](https://badge.fury.io/rb/inih)
|
6
|
+
[![Build Status](https://img.shields.io/github/workflow/status/woodruffw/ruby-inih/CI/master)](https://github.com/woodruffw/ruby-inih/actions?query=workflow%3ACI)
|
5
7
|
|
6
8
|
A Ruby wrapper for [inih](https://github.com/benhoyt/inih), a simple INI parser.
|
7
9
|
|
8
10
|
### Installation
|
9
11
|
|
10
|
-
```
|
12
|
+
```bash
|
11
13
|
$ gem install inih
|
12
14
|
```
|
13
15
|
|
@@ -35,12 +37,12 @@ INIH.parse "[section]\nkey=value"
|
|
35
37
|
#=> {"section"=>{"key"=>"value"}}
|
36
38
|
```
|
37
39
|
|
38
|
-
Integers, floating-point numbers, and booleans are coerced into their respective Ruby types
|
40
|
+
Integers, floating-point numbers, and booleans are coerced into their respective Ruby types by
|
41
|
+
default, **unless** `normalize: false` is passed to either method.
|
39
42
|
|
40
43
|
### TODO
|
41
44
|
|
42
|
-
*
|
43
|
-
* Coerce scientific-notation?
|
45
|
+
* Coerce scientific notation?
|
44
46
|
|
45
47
|
### License
|
46
48
|
|
data/ext/inih/inih.c
CHANGED
@@ -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
|
9
|
-
|
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
|
12
|
+
static VALUE mINIH_parse_intern(VALUE self, VALUE string, VALUE normalize);
|
15
13
|
|
16
14
|
/*
|
17
|
-
@overload
|
18
|
-
|
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
|
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, "
|
30
|
-
rb_define_singleton_method(mINIH, "
|
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
|
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(
|
53
|
+
rb_raise(cParseError, "parse error, line %d", result);
|
58
54
|
}
|
59
55
|
|
60
|
-
|
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
|
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(
|
72
|
+
rb_raise(rb_eIOError, "I/O error");
|
72
73
|
}
|
73
74
|
else {
|
74
|
-
rb_raise(
|
75
|
+
rb_raise(cParseError, "parse error, line %d", result);
|
75
76
|
}
|
76
77
|
}
|
77
78
|
|
78
|
-
|
79
|
+
if (normalize) {
|
80
|
+
return rb_funcall(mINIH, rb_intern("normalize_hash"), 1, hash);
|
81
|
+
}
|
82
|
+
else {
|
83
|
+
return hash;
|
84
|
+
}
|
79
85
|
}
|
data/lib/inih.rb
CHANGED
@@ -1,15 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "inih/exceptions"
|
4
|
+
require_relative "ext/inih"
|
4
5
|
|
5
6
|
# The primary namespace for {INIH}.
|
6
7
|
module INIH
|
7
|
-
|
8
|
-
|
8
|
+
module_function
|
9
|
+
|
10
|
+
# Parse an INI-formatted string into a Hash.
|
11
|
+
# @param string [String] the INI-formatted string to parse
|
12
|
+
# @param normalize [Boolean] whether or not to normalize the types of parsed values
|
13
|
+
# @return [Hash] the parsed hash
|
14
|
+
# @raise [INIH::ParseError] if a parse error occurs
|
15
|
+
def parse(string, normalize: true)
|
16
|
+
parse_intern string, normalize
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parse an INI-formatted file into a Hash.
|
20
|
+
# @param filename [String] the INI-formatted file to parse
|
21
|
+
# @param normalize [Boolean] whether or not to normalize the types of parsed values
|
22
|
+
# @return [Hash] the resulting hash
|
23
|
+
# @raise [INIH::ParseError] if a parse error occurs
|
24
|
+
# @raise [IOError] if an I/O error occurs
|
25
|
+
def load(filename, normalize: true)
|
26
|
+
load_intern filename, normalize
|
27
|
+
end
|
9
28
|
|
10
29
|
# Normalize a parsed INI file's values.
|
11
30
|
# @api private
|
12
|
-
def
|
31
|
+
def normalize_hash(hsh)
|
13
32
|
hsh.map do |k, sect|
|
14
33
|
[k, normalize_sect(sect)]
|
15
34
|
end.to_h
|
@@ -17,13 +36,14 @@ module INIH
|
|
17
36
|
|
18
37
|
# Normalize the values in a section of a parsed INI file.
|
19
38
|
# @api private
|
20
|
-
def
|
39
|
+
def normalize_sect(sect)
|
21
40
|
sect.map do |k, v|
|
22
41
|
nv = case v
|
42
|
+
when "" then nil
|
23
43
|
when "true" then true
|
24
44
|
when "false" then false
|
25
|
-
when /\A
|
26
|
-
when /\A
|
45
|
+
when /\A-?\d+\Z/ then Integer v
|
46
|
+
when /\A-?\d+\.\d+\Z/ then Float v
|
27
47
|
else v
|
28
48
|
end
|
29
49
|
|
data/lib/inih/version.rb
ADDED
@@ -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,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inih
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
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: rake-compiler
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redcarpet
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
description: A native library for parsing INI files.
|
14
70
|
email: william@tuffbizz.com
|
15
71
|
executables: []
|
@@ -27,6 +83,9 @@ files:
|
|
27
83
|
- ext/inih/inih.c
|
28
84
|
- ext/inih/inih.h
|
29
85
|
- lib/inih.rb
|
86
|
+
- lib/inih/exceptions.rb
|
87
|
+
- lib/inih/version.rb
|
88
|
+
- vendor/bundle/gems/yard-0.9.19/LICENSE
|
30
89
|
homepage: https://github.com/woodruffw/ruby-inih
|
31
90
|
licenses:
|
32
91
|
- MIT
|
@@ -46,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
105
|
- !ruby/object:Gem::Version
|
47
106
|
version: '0'
|
48
107
|
requirements: []
|
49
|
-
|
50
|
-
rubygems_version: 2.6.11
|
108
|
+
rubygems_version: 3.1.2
|
51
109
|
signing_key:
|
52
110
|
specification_version: 4
|
53
111
|
summary: inih - a Ruby wrapper for a simple C INI parser
|