nestedtext 4.2.0 → 4.2.2

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
2
  SHA256:
3
- metadata.gz: 9e3fcbca130327597aa3a6f2205d5328ddf407a916c5a071906686b5013fca52
4
- data.tar.gz: f143d0efe77a919566360830209e8ab36b8a0205feb0466c8c00b55a598da904
3
+ metadata.gz: 56edadbc6c19a780acc64f2dc5e7b433a7a5086b9c2ff5d19837d18fa84ef1cb
4
+ data.tar.gz: 0b65feaf1d2cd866c1700c19bf2329c4c0a01db97b48c7c3b18dd91ae1620969
5
5
  SHA512:
6
- metadata.gz: 1835a85442d3080bb1084aeed972d787f12325b88f99c50528858596d4918eef73101eb9861fe7a78102a17f9ed27551034a8a237f55143f26d2e74deac3b9e7
7
- data.tar.gz: 9998dd2a1d1a1afff99b5cc587a35e6cc240fe38a74c2b19fcb6dd38f3d907c414e1a644a8891832049cfa770eb2a047054e447f48bebbd4481e027eb0ad079f
6
+ metadata.gz: fa67ebde8e33b4e254f1ca484046113971141bb2fcd10e7b64aeb03cd4dab0912acfc465c521bf9a5647483536c478cc754c0602f79bf9a156c870c9e7d2974e
7
+ data.tar.gz: 9527268ebfae6a0646ce7f22f9af6f30bca4a70e8e65a233e94fd870054ebae374cc2a1aa58df4572d3128298ae8433fc8218633dcc2410665e8fd9ab895ff25
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [4.2.2] - 2022-02-12
10
+ ### Fixed
11
+ - Better module documentation fix.
12
+
13
+ ## [4.2.1] - 2022-02-12
14
+ ### Fixed
15
+ - Better module documentation.
16
+
9
17
  ## [4.2.0] - 2022-02-08
10
18
  ### Fixed
11
19
  - Proper Unicode character name lookup.
data/README.md CHANGED
@@ -146,7 +146,7 @@ Ruby | [NestedText](https://nestedtext.org/en/latest/basic_syntax.html)
146
146
 
147
147
 
148
148
  ### Strict Mode
149
- The strict mode determines how classes other than the basic types `String`, `Array` and `Hash` are handled during encoding and decoding. By **default** strict mode is turned **off**.
149
+ The strict mode determines how classes other than the basic types `String`, `Array` and `Hash` are handled during encoding and decoding. By **default** strict mode is **false**.
150
150
 
151
151
  With `strict: true`
152
152
  Ruby | NestedText | Comment
@@ -174,7 +174,7 @@ Other Class | String | `#to_s` will be called if there is no `#encode_nt_with`
174
174
  ## Custom Classes Serialization
175
175
  This library has support for serialization/deserialization of custom classes as well. This is done by letting the objects tell NestedText what data should be used to represent the object instance with the `#encode_nt_with` method (inspired by `YAML`'s `#encode_with` method). All objects being recursively referenced from a root object being serialized must either implement this method or be one of the core supported NestedText data types from the table above.
176
176
 
177
- A class implementing `#encode_nt_with` is referred to as `Custom Class` in this document.
177
+ A class implementing `#encode_nt_with` is referred to as a `Custom Class` in this document.
178
178
 
179
179
  ```ruby
180
180
  class Apple
@@ -250,8 +250,8 @@ See [encode_custom_classes_test.rb](test/nestedtext/encode_custom_classes_test.r
250
250
  # Schema
251
251
  The point of NestedText is to not get in to business of supporting ambiguous types. That's why all values are simple strings. Having only simple strings is not useful in practice though. This is why NestedText is intended to be paired with a [Schema Validator](https://nestedtext.org/en/latest/schemas.html)!
252
252
 
253
- A schema validators can:
254
- * assert that the parsed values are like the expected
253
+ A schema validator can:
254
+ * assert that the parsed values are of the expected types
255
255
  * automatically convert them to Ruby class instances like Integer, Float, etc.
256
256
 
257
257
  The reference implementation in Python [lists](https://nestedtext.org/en/latest/examples.html) a few examples of Python validators. Here below is an example of how this Ruby implementation of NestedText can be paired it with [RSchema](https://github.com/tomdalling/rschema).
@@ -259,7 +259,7 @@ The reference implementation in Python [lists](https://nestedtext.org/en/latest/
259
259
  ## Example with RSchema
260
260
  The full and working example can be found at [erikw/nestedtext-ruby-test](https://github.com/erikw/nestedtext-ruby-test/blob/main/parse_validate.rb).
261
261
 
262
- Let's say that you have a program that should connect to a few servers. The list of servers should be stored in a configuration file. With NestedText, this file could look like:
262
+ Let's say that you have a program that should connect to a few servers. The list of servers should be stored in a configuration file. With NestedText, a `conf.nt` file could look like:
263
263
  ```yaml
264
264
  -
265
265
  name: global-service
@@ -273,7 +273,7 @@ Let's say that you have a program that should connect to a few servers. The list
273
273
  stable: false
274
274
  ```
275
275
 
276
- After parsing this file with this NestedText library, the values for all keys will be string. But for to make practical use of this, we would of course like the values for `port` to be `Integer`, and `stable` should have a value of either `true` or `false`. RSchema can do this conversion for us!
276
+ After parsing this file with this NestedText library, the values for all keys will be string. But to make practical use of this, we would of course like the values for the `port` keys to be `Integer`, and `stable` should have a value of either `true` or `false`. RSchema can do this conversion for us!
277
277
 
278
278
 
279
279
  ```ruby
@@ -296,18 +296,16 @@ coercer = RSchema::CoercionWrapper::RACK_PARAMS.wrap(schema)
296
296
  data = NestedText.load_file('conf.nt')
297
297
 
298
298
  # Validate
299
- result = coercer.validate(data_success)
300
-
301
- if result.valid?
302
- servers = result.value
303
- # Now 'servers' is known to be valid and have the types specified in the schema.
304
- # Thus, we can use it now!
305
- stable_servers = servers.select { |server| server['stable'] }
306
- # Not a meaningful sum - just demonstrating that 'port's are integers and not strings anymore!
307
- port_sum = servers.map { |server| server['port'] }.sum
308
- else
309
- puts result.error
310
- end
299
+ result = coercer.validate(data)
300
+ raise result.error.to_s unless result.valid?
301
+
302
+ # Now we have validated data of the right type specified in the schema!
303
+ servers = result.value
304
+
305
+ # Let's use the values for something in our app
306
+ stable_servers = servers.select { |server| server['stable'] }
307
+ # Not a meaningful sum - just demonstrating that 'port' values are integers and not strings anymore!
308
+ port_sum = servers.map { |server| server['port'] }.sum
311
309
  ```
312
310
 
313
311
  # Installation
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'word_wrap'
4
- require 'word_wrap/core_ext'
3
+ # require 'word_wrap'
4
+ # require 'word_wrap/core_ext'
5
5
  require 'unicode_utils'
6
6
 
7
7
  require 'nestedtext/constants'
@@ -141,9 +141,10 @@ module NestedText
141
141
  else
142
142
  'invalid indentation.'
143
143
  end
144
- # Need to wrap like official tests. #wrap always add an extra \n we need to chop off.
145
- message_wrapped = message.wrap(70).chop
146
- super(line, ind_exp, message_wrapped)
144
+ # Official-tests kludge; Need to wrap like official tests. #wrap always add an extra \n we need to chop off.
145
+ # Seems not be needed anymore
146
+ # message_wrapped = message.wrap(70).chop
147
+ super(line, ind_exp, message)
147
148
  end
148
149
  end
149
150
 
@@ -164,11 +165,12 @@ module NestedText
164
165
  class ParseInvalidIndentationCharError < ParseError
165
166
  def initialize(line)
166
167
  char = line.content[0]
167
- # Official-test kludge; Translate rubys \u00 to python's unicodedata.name \x format.
168
+ # Official-tests kludge; Translate rubys \u00 to python's unicodedata.name \x format.
168
169
  printable_char = char.dump.gsub(/"/, '').gsub(/\\u0*/, '\x').downcase
169
170
 
170
171
  explanation = ''
171
- # Official-test kludge; ASCII chars have printable names too, but they are not used in reference implementation.
172
+ # Official-tests kludge; ASCII chars have printable names too,
173
+ # but they are not used in reference implementation.
172
174
  explanation = " (#{UnicodeUtils.char_name(char)})" unless char.ord < 128
173
175
 
174
176
  message = "invalid character in indentation: '#{printable_char}'#{explanation}."
@@ -225,7 +227,7 @@ module NestedText
225
227
 
226
228
  class DumpUnsupportedTypeError < DumpError
227
229
  def initialize(obj, culprit)
228
- # Needed to pass official test.
230
+ # Official-tests kludge; translate to Python names
229
231
  class_name = obj.is_a?(Integer) ? 'int' : obj.class.name
230
232
  super(culprit, "unsupported type (#{class_name}).")
231
233
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module NestedText
4
4
  # The version of this library.
5
- VERSION = '4.2.0'
5
+ VERSION = '4.2.2'
6
6
  end
data/lib/nestedtext.rb CHANGED
@@ -7,9 +7,12 @@ require_relative 'nestedtext/encode_helpers'
7
7
  require_relative 'nestedtext/error'
8
8
  require_relative 'nestedtext/version'
9
9
 
10
- ##
11
10
  # # NestedText
12
- # The main module in this library to use.
11
+ # A ruby library for the human friendly data format NestedText (https://nestedtext.org/).
12
+ #
13
+ # Provided is support for decoding a NestedText file or string to Ruby data structures,
14
+ # as well as encoding Ruby objects to a NestedText file or string. Furthermore there is
15
+ # support for serialization and deserialization of custom classes.
13
16
  #
14
17
  # See {file:README.md} for documentation on Types, Strict Mode and Custom Classes.
15
18
  module NestedText
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nestedtext
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Westrup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2022-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode_utils