ree_lib 1.0.65 → 1.0.66

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: e6a080727db9b2998d5e983aa2e024fd73833e6b98deb2f75eb8ac8309af1c6b
4
- data.tar.gz: b96cc24d1df8586e8159e96c7545017ecab7009a01bd5b9a2b9c759fb1beeddd
3
+ metadata.gz: e4afa1450a6827106e39ef7e907de9ce4f490a2cc323bbc59eca1c5cf7386b69
4
+ data.tar.gz: 2a7e3858a80590ad65ce462f77d61f1e5d87435fdf9b5528c626ed41a573cb5c
5
5
  SHA512:
6
- metadata.gz: c1a8e3c1d0471a58cb3dd4602a83a8da2f30498e4af39f9ade709a256592d8f3a6ef6c58a14a8fff1c3f865d9508c49e5673d4bbbe8d0ddbe95fa5dd37074695
7
- data.tar.gz: 34e1a0221ad4040a469082111c63687903e6e5d6a89d25c8ada10f742efbd6774e0e8bc729c251670a5ef293b4917dfebe3c701be6155f84241a4a651d952b9c
6
+ metadata.gz: 6a2d3070cbe58af3289dd89da27004955d4689a2b32758b7dd123288e6fabcc1915571ee6b353cd8edd0beaef8402f9668bf8034742a7ab30359d26b1f7828a3
7
+ data.tar.gz: 3eb4943530aa4e658f091ce8d8314032b9b5381828ec04e82686ecea3ec2a6481d56783eb19a8d86a943d3108a846632ff0903ec2a28b164734792f9e20322ae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.65)
4
+ ree_lib (1.0.66)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -11,7 +11,7 @@ class ReeJson::Constants
11
11
  :object,
12
12
  :custom,
13
13
  :wab,
14
- ]
14
+ ].freeze
15
15
 
16
16
  ESCAPE_MODES = [
17
17
  :newline, # allows unescaped newlines in the output.
@@ -19,12 +19,13 @@ class ReeJson::Constants
19
19
  :xss_safe, # escapes HTML and XML characters such as & and <.
20
20
  :ascii, # escapes all non-ascii or characters with the hi-bit set.
21
21
  :unicode_xss, # escapes a special unicodes and is xss safe.
22
- ]
22
+ ].freeze
23
23
 
24
- TIME_FORMATS = []
24
+ TIME_FORMATS = [].freeze
25
25
 
26
26
  DEFAULT_OPTIONS = {
27
27
  time_format: :xmlschema,
28
- use_as_json: true
28
+ use_as_json: true,
29
+ mode: :rails,
29
30
  }.freeze
30
31
  end
@@ -3,7 +3,7 @@ class ReeJson::FromJson
3
3
 
4
4
  fn :from_json do
5
5
  link 'ree_json/constants', -> {
6
- DEFAULT_OPTIONS & MODES & ESCAPE_MODES & TIME_FORMATS
6
+ DEFAULT_OPTIONS & MODES & ESCAPE_MODES & TIME_FORMATS
7
7
  }
8
8
  end
9
9
 
@@ -11,23 +11,18 @@ class ReeJson::FromJson
11
11
 
12
12
  contract(
13
13
  Any,
14
- Kwargs[
15
- mode: Or[*MODES]
16
- ],
17
14
  Ksplat[
15
+ mode?: Or[*MODES],
18
16
  symbol_keys?: Bool,
19
17
  RestKeys => Any
20
- ] => Hash
18
+ ] => Any
21
19
  ).throws(ParseJsonError)
22
- def call(object, mode: :rails, **opts)
20
+ def call(object, **opts)
23
21
  options = DEFAULT_OPTIONS
24
- .dup
25
- .merge(
26
- opts.merge(mode: mode)
27
- )
22
+ .merge(opts)
28
23
 
29
24
  Oj.load(object, options)
30
- rescue ArgumentError, EncodingError
25
+ rescue ArgumentError, EncodingError, TypeError
31
26
  raise ParseJsonError.new
32
27
  end
33
28
  end
@@ -18,10 +18,8 @@ class ReeJson::ToJson
18
18
 
19
19
  contract(
20
20
  Any,
21
- Kwargs[
22
- mode: Or[*MODES]
23
- ],
24
21
  Ksplat[
22
+ mode?: Or[*MODES],
25
23
  escape_mode?: Or[*ESCAPE_MODES],
26
24
  float_precision?: Integer,
27
25
  time_format?: Or[*TIME_FORMATS],
@@ -31,13 +29,10 @@ class ReeJson::ToJson
31
29
  use_to_json?: Bool,
32
30
  RestKeys => Any
33
31
  ] => String
34
- ).throws(ArgumentError)
35
- def call(object, mode: :rails, **opts)
32
+ ).throws(ArgumentError, TypeError)
33
+ def call(object, **opts)
36
34
  options = DEFAULT_OPTIONS
37
- .dup
38
- .merge(
39
- opts.merge(mode: mode)
40
- )
35
+ .merge(opts)
41
36
 
42
37
  Oj.dump(object, options)
43
38
  end
@@ -12,22 +12,17 @@
12
12
  "throws": [
13
13
  "ReeJson::FromJson::ParseJsonError"
14
14
  ],
15
- "return": "Hash",
15
+ "return": "Any",
16
16
  "args": [
17
17
  {
18
18
  "arg": "object",
19
19
  "arg_type": "req",
20
20
  "type": "Any"
21
21
  },
22
- {
23
- "arg": "mode",
24
- "arg_type": "key",
25
- "type": "Or[strict, null, compat, json, rails, object, custom, wab]"
26
- },
27
22
  {
28
23
  "arg": "opts",
29
24
  "arg_type": "keyrest",
30
- "type": "Ksplat[:symbol_keys? => Bool, \"RestKeys\" => Any]"
25
+ "type": "Ksplat[:mode? => Or[strict, null, compat, json, rails, object, custom, wab], :symbol_keys? => Bool, \"RestKeys\" => Any]"
31
26
  }
32
27
  ]
33
28
  }
@@ -10,7 +10,8 @@
10
10
  {
11
11
  "doc": "Dumps arbitrary object to json using specific dump mode.\n to_json({id: 1}) # => \"{\"id\":1}\"\n to_json({id: 1}, mode: :object) # => \"{\":id\":{\"^o\":\"Object\"}}\"\n\nList of all available Ksplat options could be found here:\nhttps://github.com/ohler55/oj/blob/develop/pages/Modes.md",
12
12
  "throws": [
13
- "ArgumentError"
13
+ "ArgumentError",
14
+ "TypeError"
14
15
  ],
15
16
  "return": "String",
16
17
  "args": [
@@ -19,15 +20,10 @@
19
20
  "arg_type": "req",
20
21
  "type": "Any"
21
22
  },
22
- {
23
- "arg": "mode",
24
- "arg_type": "key",
25
- "type": "Or[strict, null, compat, json, rails, object, custom, wab]"
26
- },
27
23
  {
28
24
  "arg": "opts",
29
25
  "arg_type": "keyrest",
30
- "type": "Ksplat[:escape_mode? => Or[newline, json, xss_safe, ascii, unicode_xss...], :float_precision? => Integer, :time_format? => Or[], :use_as_json? => Bool, :use_raw_json? => Bool, :use_to_hash? => Bool, :use_to_json? => Bool, \"RestKeys\" => Any]"
26
+ "type": "Ksplat[:mode? => Or[strict, null, compat, json, rails, object, custom, wab], :escape_mode? => Or[newline, json, xss_safe, ascii, unicode_xss...], :float_precision? => Integer, :time_format? => Or[], :use_as_json? => Bool, :use_raw_json? => Bool, :use_to_hash? => Bool, :use_to_json? => Bool, \"RestKeys\" => Any]"
31
27
  }
32
28
  ]
33
29
  }
@@ -12,7 +12,39 @@ RSpec.describe :from_json do
12
12
  expect(result[:id]).to be_a(Object)
13
13
  }
14
14
 
15
+ it {
16
+ expect(from_json("null")).to eq(nil)
17
+ }
18
+
19
+ it {
20
+ expect(from_json("true")).to eq(true)
21
+ }
22
+
23
+ it {
24
+ expect(from_json('"hello"')).to eq("hello")
25
+ }
26
+
27
+ it {
28
+ expect(from_json("123")).to eq(123)
29
+ }
30
+
31
+ it {
32
+ expect(from_json("123.456")).to eq(123.456)
33
+ }
34
+
35
+ it {
36
+ expect(from_json("[1,true,\"hello\"]")).to eq([1, true, "hello"])
37
+ }
38
+
39
+ it {
40
+ expect(from_json("{\"^o\":\"Object\"}", mode: :object)).to be_a(Object)
41
+ }
42
+
15
43
  it {
16
44
  expect{from_json("{213: \"123\"}")}.to raise_error(ReeJson::FromJson::ParseJsonError)
17
45
  }
46
+
47
+ it {
48
+ expect { from_json(nil, mode: :strict) }.to raise_error(ReeJson::FromJson::ParseJsonError)
49
+ }
18
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.65"
4
+ VERSION = "1.0.66"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.65
4
+ version: 1.0.66
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-01 00:00:00.000000000 Z
11
+ date: 2023-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree