ryo.rb 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/lib/ryo/json.rb +22 -20
- data/lib/ryo/version.rb +1 -1
- data/spec/ryo_json_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b39f30dc20ead80a6704d27f1a10b9046ad6fe05d164ec4cb31b6606f225a33
|
4
|
+
data.tar.gz: 03db26bce85e7f1fad10d2b909284c32fc18f13cd999aa718ddd21d867d29a29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f73de92d97038eb2ef3c70c4fb97e02c84a0ed5fe9a7d73f198f392f4a04ca608170ab2011f537bac9779cb66c7214a1166040268d602aa592a540789e24e8
|
7
|
+
data.tar.gz: 51809089becfa72d4cadf79771cd944f1d31e8d658d03f4d00881c6d7eec6dbd58448cbabe3efada8e386a55c96b5298fb47470f76c125179ecf35ad9d1ddb1b
|
data/README.md
CHANGED
@@ -333,9 +333,12 @@ p point.x # => 5
|
|
333
333
|
p point.y # => 10
|
334
334
|
```
|
335
335
|
|
336
|
-
##
|
336
|
+
## Documentation
|
337
|
+
|
338
|
+
A complete API reference is available at
|
339
|
+
[0x1eef.github.io/x/ryo.rb](https://0x1eef.github.io/x/ryo.rb)
|
337
340
|
|
338
|
-
|
341
|
+
## Install
|
339
342
|
|
340
343
|
Ryo can be installed via rubygems.org:
|
341
344
|
|
data/lib/ryo/json.rb
CHANGED
@@ -10,33 +10,35 @@ module Ryo::JSON
|
|
10
10
|
extend self
|
11
11
|
|
12
12
|
##
|
13
|
+
# @example
|
14
|
+
# Ryo.from_json(path: "/foo/bar/baz.json")
|
15
|
+
# Ryo.from_json(string: "[]")
|
16
|
+
#
|
13
17
|
# @param [String] path
|
14
|
-
# The path to a JSON file
|
18
|
+
# The path to a JSON file
|
19
|
+
#
|
20
|
+
# @param [String] string
|
21
|
+
# A blob of JSON
|
15
22
|
#
|
16
23
|
# @param [Ryo] object
|
17
|
-
# {Ryo::Object Ryo::Object}, or {Ryo::BasicObject Ryo::BasicObject}
|
18
|
-
# Defaults to {Ryo::Object Ryo::Object}
|
24
|
+
# {Ryo::Object Ryo::Object}, or {Ryo::BasicObject Ryo::BasicObject}
|
25
|
+
# Defaults to {Ryo::Object Ryo::Object}
|
19
26
|
#
|
20
27
|
# @raise [SystemCallError]
|
21
|
-
# Might raise a number of Errno exceptions
|
28
|
+
# Might raise a number of Errno exceptions
|
22
29
|
#
|
23
30
|
# @return [Ryo::Object, Ryo::BasicObject]
|
24
|
-
# Returns a Ryo object
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# Defaults to {Ryo::Object Ryo::Object}.
|
36
|
-
#
|
37
|
-
# @return (see Ryo::JSON#from_json_file)
|
38
|
-
def from_json(blob, object: Ryo::Object)
|
39
|
-
object.from JSON.parse(blob)
|
31
|
+
# Returns a Ryo object
|
32
|
+
def from_json(path: nil, string: nil, object: Ryo::Object)
|
33
|
+
if path && string
|
34
|
+
raise ArgumentError, "Provide a path or string but not both"
|
35
|
+
elsif path
|
36
|
+
object.from JSON.parse(File.binread(path))
|
37
|
+
elsif string
|
38
|
+
object.from JSON.parse(string)
|
39
|
+
else
|
40
|
+
raise ArgumentError, "No path or string provided"
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
Ryo.extend(self)
|
data/lib/ryo/version.rb
CHANGED
data/spec/ryo_json_spec.rb
CHANGED
@@ -6,7 +6,7 @@ require "fileutils"
|
|
6
6
|
|
7
7
|
RSpec.describe Ryo::JSON do
|
8
8
|
describe ".from_json_file" do
|
9
|
-
subject(:ryo) { described_class.
|
9
|
+
subject(:ryo) { described_class.from_json(path:, object:) }
|
10
10
|
before { File.binwrite path, JSON.dump(x: 20, y: 40) }
|
11
11
|
after { FileUtils.rm(path) }
|
12
12
|
let(:path) { File.join(__dir__, "test.json") }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ryo.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|