nestedtext 0.5.0 → 1.1.1

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: 7544291bb0f2d8e67327370b56ab6c8b362f5d5ede745c24730187749998ec16
4
- data.tar.gz: '08e4f57165ea3e9c85158c4f215c14ce23a54bf2c39b553fea9292f48dbd4e96'
3
+ metadata.gz: 75a2d51a9136b92dfc3ca5c7d41172107a51ec9d330b0553c992a86d32156179
4
+ data.tar.gz: b28add9673b21617c99fe4573794c44ee04a0c49c003ced761540fab4f4b1a55
5
5
  SHA512:
6
- metadata.gz: dee4eb7841df29f0c61d7ca3afd84e187a3437e02037517bab844da5ad5ef53c2687b6dada8f64041cec48968f8093de1ccc86395b1a5ae5cefa56240e66fb81
7
- data.tar.gz: 0aa5dd31a6373f119677b3d0796e4465373fc60efb1ee2ec7521d10555e38e34a9cd0f48e30eab0dbb7dd14c2de7610e6b74d2b8f448d87877c7cfc25f3b4079
6
+ metadata.gz: 7f7147ac293908f5cf6aa67175f0a0bf5f0b0dbc68fda541c58e045edbba88e176cd1dffd8e18004fa8848f385c62ae8df1124d8c60afca8ac47231b54cb50bb
7
+ data.tar.gz: 00b93d7103d7a8aee1c4c4902ff5a935ceb0760265a776ad837a845b8992869f47b704dfed4cdd6c7788df567f64ab0d936494ef52bfff15302c8693f3f045cd
data/CHANGELOG.md CHANGED
@@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.1] - 2022-01-25
10
+ ### Fixed
11
+ - Renamed `NTEncodeMixing` to `NTEncodeMixin` .
12
+
13
+ ## [1.1.0] - 2022-01-25
14
+ ### Added
15
+ - Expose `NestedText::VERSION` for convenience to the clients.
16
+
17
+ ## [1.0.0] - 2022-01-25
18
+ The library is now useful for clients!
19
+
20
+ ### Changed
21
+ - Hide all internals in the module from clients.
22
+
23
+ ## [0.6.0] - 2022-01-24
24
+ ### Fixed
25
+ - Move runtime dependencies from Gemfile to .gemspec.
26
+
9
27
  ## [0.5.0] - 2022-01-24
10
28
  ### Added
11
29
  - Publish Gem to GitHub Packages
data/Gemfile CHANGED
@@ -12,7 +12,6 @@ gemspec
12
12
  # Reference: https://github.com/rubygems/bundler/pull/7222
13
13
  # However there's an argument for using gemspec too: https://bundler.io/guides/creating_gem.html#testing-our-gem
14
14
  group :development, :test do
15
- gem "appraisal", "~> 2.4", require: false
16
15
  gem "gem-release", "~> 2.0", require: false
17
16
  gem "pry-byebug", "~> 3.9"
18
17
  gem "rake", "~> 13.0", require: false
@@ -26,6 +25,3 @@ group :test do
26
25
  gem "rubocop-rake", "~> 0.6", require: false
27
26
  gem "simplecov", "~> 0.21", require: false
28
27
  end
29
-
30
- gem "warning", "~> 1.2"
31
- gem "word_wrap", "~> 1.0"
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # NestedText Ruby Library [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Get%20a%20nifty%20tooltip%20for%20term%20definitions%20in%20your%20Jekyll%20blog%20with%20this%20plugin&url=https://github.com/erikw/nestedtext-ruby&via=erik_westrup&hashtags=jekyll,plugin)
1
+ # NestedText Ruby Library [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=NestedText,%20the%20human%20friendly%20data%20format,%20has%20a%20now%20a%20ruby%20library%20for%20easy%20encoding%20and%20decoding&url=https://github.com/erikw/nestedtext-ruby&via=erik_westrup&hashtags=nestedtext,ruby,gem)
2
2
  [![Gem Version](https://badge.fury.io/rb/nestedtext.svg)](https://badge.fury.io/rb/nestedtext)
3
3
  [![Gem Downloads](https://ruby-gem-downloads-badge.herokuapp.com/nestedtext?color=brightgreen&type=total&label=gem%20downloads)](https://rubygems.org/gems/nestedtext)
4
4
  [![Data Format Version Supported](https://img.shields.io/badge/%F0%9F%84%BD%F0%9F%85%83%20Version%20Supported-3.2.1-blueviolet)](https://nestedtext.org/en/v3.2/)
5
- [![GitHub Actions: Continuous Integration](https://github.com/erikw/nestedtext-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/erikw/nestedtext-ruby/actions/workflows/ci.yml)
6
5
  [![Official Tests](https://img.shields.io/badge/%F0%9F%8F%81%20Official%20Tests-Passing-success)](https://github.com/KenKundert/nestedtext_tests/tree/585e95a73d94ac1f48e71a154e2db0ab67cf30fa)
6
+ [![GitHub Actions: Continuous Integration](https://github.com/erikw/nestedtext-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/erikw/nestedtext-ruby/actions/workflows/ci.yml)
7
7
  [![GitHub Actions: Continuous Deployment](https://github.com/erikw/nestedtext-ruby/actions/workflows/cd.yml/badge.svg)](https://github.com/erikw/nestedtext-ruby/actions/workflows/cd.yml)
8
8
  [![GitHub Actions: CodeQL Analysis](https://github.com/erikw/nestedtext-ruby/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/erikw/nestedtext-ruby/actions/workflows/codeql-analysis.yml)
9
9
  [![Code Climate Maintainability](https://api.codeclimate.com/v1/badges/8409b6cdc3dc62a33f6f/maintainability)](https://codeclimate.com/github/erikw/nestedtext-ruby/maintainability)
@@ -22,12 +22,14 @@ On-going development is at branch [**dev**](https://github.com/erikw/nestedtext-
22
22
  # What is NestedText?
23
23
  TODO
24
24
 
25
+ https://nestedtext.org/en/latest/alternatives.html
26
+
25
27
  ## Examples
26
28
  TODO NT examples
27
29
 
28
30
  # Usage
29
31
  TODO Link to lib docs
30
- TODO link to my test repo showin live usage.
32
+ TODO link to my test repo showin live usage. https://github.com/erikw/nestedtext-ruby-test
31
33
 
32
34
 
33
35
  # Usage
@@ -35,6 +37,25 @@ TODO link to my test repo showin live usage.
35
37
 
36
38
  ## Encoding (writing NT)
37
39
 
40
+ `#to_nt` method:
41
+ ```irb
42
+ irb> require 'nestedtext'
43
+ irb> puts "a\nstring".to_nt
44
+ > a
45
+ > string
46
+ irb> puts ["i1", "i2", "i3"].to_nt
47
+ - i1
48
+ - i2
49
+ - i3
50
+ irb> puts({"k1" => "v1", "multiline\nkey" => "v2", "k3" => "multiline\nvalue"}.to_nt)
51
+ k1: v1
52
+ : multiline
53
+ : key
54
+ > v2
55
+ k3:
56
+ > multiline
57
+ > value
58
+ ```
38
59
  ## Custom Classes Serialization
39
60
  This library has support for serialization/deserialization of custom classes as well.
40
61
  `strict: false` flag needed
@@ -70,9 +91,16 @@ See [encode_custom_classes_test.rb](test/nestedtext/encode_custom_classes_test.r
70
91
  1. Install a supported ruby version (see .gemspec) with a ruby version manager e.g. [rbenv](https://github.com/rbenv/rbenv), [asdf](http://asdf-vm.com/) or [RVM](https://rvm.io/rvm/install)
71
92
  1. run `$ script/setup` to install dependencies
72
93
  1. run `$ script/test` to run the tests
73
- 1. You can also run `$ script/console` for an interactive prompt that will allow you to experiment.
94
+ 1. You can also run `$ script/console` for an interactive prompt that will allow you to experiment.
95
+ 1. For local testing, install the gem on local machine with: `$ bundle exec rake install`.
96
+ * or manuall with `$ gem build *.gemscpec && gem install *.gem`
74
97
 
75
- To install this gem onto your local machine, run `$ bundle exec rake install`.
98
+ Make sure that only intended constants and methods are exposed from the module `NestedText`. Check with
99
+ ```
100
+ irb> require 'nestedtext'
101
+ irb> NestedText.constants
102
+ irb> NestedText.methods(false)
103
+ ```
76
104
 
77
105
  ## Releasing
78
106
  Instructions for releasing on rubygems.org below. Optionally make a GitHub [release](https://github.com/erikw/nestedtext-ruby/releases) after this for the pushed git tag.
data/SECURITY.md CHANGED
@@ -5,7 +5,7 @@
5
5
  | Version | Supported |
6
6
  | ------- | ------------------ |
7
7
  | 1.x.x | :white_check_mark: |
8
- | < 1.0 | :x: |
8
+ | < 1.1.1 | :x: |
9
9
 
10
10
 
11
11
  ## Reporting a Vulnerability
@@ -2,4 +2,6 @@ require "stringio"
2
2
  module NestedText
3
3
  TOP_LEVEL_TYPES = [Object, Hash, Array, String]
4
4
  CUSTOM_CLASS_KEY = "__nestedtext_class__"
5
+
6
+ private_constant :TOP_LEVEL_TYPES, :CUSTOM_CLASS_KEY
5
7
  end
@@ -5,12 +5,13 @@ require "nestedtext/encode_helpers"
5
5
  # Or both: add encoding/decoding of more native classes, and allow decoding + applying a schema with 3rd party.
6
6
  # Or encourage using Marshal from core?
7
7
 
8
- class String include NestedText::NTEncodeStrictMixing end
9
- class Array include NestedText::NTEncodeStrictMixing end
10
- class Hash include NestedText::NTEncodeStrictMixing end
8
+ NT_MIXIN = NestedText.const_get(:NTEncodeStrictMixin)
9
+ class String include NT_MIXIN end
10
+ class Array include NT_MIXIN end
11
+ class Hash include NT_MIXIN end
11
12
 
12
13
  class NilClass
13
- include NestedText::NTEncodeStrictMixing
14
+ include NT_MIXIN
14
15
 
15
16
  def self.nt_create(_data) = nil
16
17
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "nestedtext/parser"
4
4
  require "nestedtext/errors"
5
- require "nestedtext/helpers"
6
5
 
7
6
  require "logger"
8
7
  require "stringio"
@@ -15,16 +14,12 @@ module NestedText
15
14
 
16
15
  raise Errors::WrongInputTypeError.new([String], ntstring) unless ntstring.nil? || ntstring.is_a?(String)
17
16
 
18
- assert_valid_top_level_type top_class
19
-
20
17
  Parser.new(StringIO.new(ntstring), top_class, strict: strict).parse
21
18
  end
22
19
 
23
20
  def self.load_file(filename, top_class: Object, strict: true)
24
21
  raise Errors::WrongInputTypeError.new([String], filename) unless !filename.nil? && filename.is_a?(String)
25
22
 
26
- assert_valid_top_level_type top_class
27
-
28
23
  # Open explicitly in text mode to detect \r as line ending.
29
24
  File.open(filename, mode = "rt") do |file|
30
25
  Parser.new(file, top_class, strict: strict).parse
@@ -174,4 +174,5 @@ module NestedText
174
174
  end
175
175
  end
176
176
  end
177
+ private_constant :Dumper
177
178
  end
@@ -1,13 +1,14 @@
1
1
  require "nestedtext/dumper"
2
2
 
3
3
  module NestedText
4
- module NTEncodeStrictMixing
4
+ module NTEncodeStrictMixin
5
5
  def to_nt(indentation: 4, strict: true)
6
6
  Dumper.new(EncodeOptions.new(indentation, strict)).dump self
7
7
  end
8
8
  end
9
+ private_constant :NTEncodeStrictMixin
9
10
 
10
- module NTEncodeMixing
11
+ module NTEncodeMixin
11
12
  def to_nt(indentation: 4)
12
13
  Dumper.new(EncodeOptions.new(indentation, false)).dump self
13
14
  end
@@ -21,4 +22,5 @@ module NestedText
21
22
  @strict = strict
22
23
  end
23
24
  end
25
+ private_constant :EncodeOptions
24
26
  end
@@ -6,12 +6,19 @@ require "word_wrap/core_ext"
6
6
  require "nestedtext/constants"
7
7
 
8
8
  module NestedText
9
- # Top level ParseError for clients to rescue.
10
- class Error < StandardError; end
9
+ # Top level error for clients to rescue on.
10
+ # TODO hide #new so that client's cant create instance of it. Unit test this. https://ruby-doc.org/core-3.1.0/Module.html#private_class_method-method
11
+ class Error < StandardError
12
+ private_class_method :new
13
+ end
11
14
 
12
15
  module Errors
16
+ class InternalError < Error
17
+ public_class_method :new # Prevent clients from instansiating.
18
+ end
19
+
13
20
  # TODO: rename all Subclasses to ParseXError, just like for Dump
14
- class ParseError < Error
21
+ class ParseError < InternalError
15
22
  attr_reader :lineno, :colno, :message_raw
16
23
 
17
24
  def initialize(line, colno, message)
@@ -177,25 +184,7 @@ module NestedText
177
184
  end
178
185
  end
179
186
 
180
- class UnsupportedTopLevelTypeError < Error
181
- def initialize(type_class)
182
- super("The given top level type #{type_class&.name} is unsupported. Chose between #{TOP_LEVEL_TYPES.join(", ")}.")
183
- end
184
- end
185
-
186
- class WrongInputTypeError < Error
187
- def initialize(class_exps, class_act)
188
- super("The given input type #{class_act.class.name} is unsupported. Expected to be of types #{class_exps.map(&:name).join(", ")}")
189
- end
190
- end
191
-
192
- class TopLevelTypeMismatchParsedType < Error
193
- def initialize(class_exp, class_act)
194
- super("The requested top level class #{class_exp.name} is not the same as the actual parsed top level class #{class_act}.")
195
- end
196
- end
197
-
198
- class AssertionError < Error; end
187
+ class AssertionError < InternalError; end
199
188
 
200
189
  class LineScannerIsEmpty < AssertionError
201
190
  def initialize
@@ -209,19 +198,7 @@ module NestedText
209
198
  end
210
199
  end
211
200
 
212
- class DumpBadIO < Error
213
- def initialize(io)
214
- super("When giving the io argument, it must be of type IO (respond to #write, #fsync). Given: #{io.class.name}")
215
- end
216
- end
217
-
218
- class DumpFileBadPath < Error
219
- def initialize(path)
220
- super("Must supply a string to a file path that can be written to. Given: #{path}")
221
- end
222
- end
223
-
224
- class DumpError < Error
201
+ class DumpError < InternalError
225
202
  attr_reader :culprit
226
203
 
227
204
  def initialize(culprit, message)
@@ -258,5 +235,36 @@ module NestedText
258
235
 
259
236
  raise LineTagNotDetected, line
260
237
  end
238
+
239
+ class UnsupportedTopLevelTypeError < InternalError
240
+ def initialize(type_class)
241
+ super("The given top level type #{type_class&.name} is unsupported. Chose between #{TOP_LEVEL_TYPES.join(", ")}.")
242
+ end
243
+ end
244
+
245
+ class WrongInputTypeError < InternalError
246
+ def initialize(class_exps, class_act)
247
+ super("The given input type #{class_act.class.name} is unsupported. Expected to be of types #{class_exps.map(&:name).join(", ")}")
248
+ end
249
+ end
250
+
251
+ class TopLevelTypeMismatchParsedType < InternalError
252
+ def initialize(class_exp, class_act)
253
+ super("The requested top level class #{class_exp.name} is not the same as the actual parsed top level class #{class_act}.")
254
+ end
255
+ end
256
+
257
+ class DumpBadIO < InternalError
258
+ def initialize(io)
259
+ super("When giving the io argument, it must be of type IO (respond to #write, #fsync). Given: #{io.class.name}")
260
+ end
261
+ end
262
+
263
+ class DumpFileBadPath < InternalError
264
+ def initialize(path)
265
+ super("Must supply a string to a file path that can be written to. Given: #{path}")
266
+ end
267
+ end
261
268
  end
269
+ private_constant :Errors
262
270
  end
@@ -4,14 +4,20 @@ require "stringio"
4
4
 
5
5
  require "nestedtext/errors"
6
6
  require "nestedtext/scanners"
7
- require "nestedtext/helpers"
7
+ require "nestedtext/constants"
8
8
 
9
9
  module NestedText
10
10
  class Parser
11
+ def self.assert_valid_top_level_type(top_class)
12
+ unless !top_class.nil? && top_class.is_a?(Class) && TOP_LEVEL_TYPES.map(&:object_id).include?(top_class.object_id)
13
+ raise Errors::UnsupportedTopLevelTypeError, top_class
14
+ end
15
+ end
16
+
11
17
  # TODO: document that caller is responsible for closing IO after done with Parser.
12
18
  def initialize(io, top_class, strict: true)
13
19
  assert_valid_input_type io
14
- NestedText.assert_valid_top_level_type(top_class)
20
+ Parser.assert_valid_top_level_type(top_class)
15
21
  @top_class = top_class
16
22
  @strict = strict
17
23
  @line_scanner = LineScanner.new(io)
@@ -284,4 +290,5 @@ module NestedText
284
290
  result
285
291
  end
286
292
  end
293
+ private_constant :Parser
287
294
  end
@@ -40,6 +40,7 @@ module NestedText
40
40
  @next_line = line
41
41
  end
42
42
  end
43
+ private_constant :LineScanner
43
44
 
44
45
  class InlineScanner
45
46
  attr_reader :line, :pos
@@ -68,6 +69,7 @@ module NestedText
68
69
  empty? ? nil : @line.content[@pos]
69
70
  end
70
71
  end
72
+ private_constant :InlineScanner
71
73
 
72
74
  class Line
73
75
  # Reference: https://nestedtext.org/en/latest/file_format.html
@@ -158,4 +160,5 @@ module NestedText
158
160
  end
159
161
  end
160
162
  end
163
+ private_constant :Line
161
164
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NestedText
4
- VERSION = "0.5.0"
4
+ VERSION = "1.1.1"
5
5
  end
data/lib/nestedtext.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "nestedtext/encode"
4
4
  require_relative "nestedtext/decode"
5
5
  require_relative "nestedtext/core_ext"
6
+ require_relative "nestedtext/version"
6
7
 
7
8
  module NestedText
8
9
  end
data/nestedtext.gemspec CHANGED
@@ -30,4 +30,7 @@ Gem::Specification.new do |spec|
30
30
  end
31
31
  end
32
32
  spec.require_paths = ["lib"]
33
+
34
+ spec.add_runtime_dependency "warning", "~> 1.2"
35
+ spec.add_runtime_dependency "word_wrap", "~> 1.0"
33
36
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nestedtext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.1.1
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-01-24 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: warning
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: word_wrap
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
13
41
  description: A ruby library implementation for the human friendly data format NestedText
14
42
  (https://nestedtext.org/). There is support for decoding a NestedText file or string
15
43
  to Ruby data structures, as well as encoding Ruby objects to a NestedText file or
@@ -40,7 +68,6 @@ files:
40
68
  - lib/nestedtext/encode.rb
41
69
  - lib/nestedtext/encode_helpers.rb
42
70
  - lib/nestedtext/errors.rb
43
- - lib/nestedtext/helpers.rb
44
71
  - lib/nestedtext/parser.rb
45
72
  - lib/nestedtext/scanners.rb
46
73
  - lib/nestedtext/version.rb
@@ -1,7 +0,0 @@
1
- module NestedText
2
- def self.assert_valid_top_level_type(top_class)
3
- unless !top_class.nil? && top_class.is_a?(Class) && TOP_LEVEL_TYPES.map(&:object_id).include?(top_class.object_id)
4
- raise Errors::UnsupportedTopLevelTypeError, top_class
5
- end
6
- end
7
- end