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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ad842754d7d2a619c1fd552527e519b41ddf36f704c7d4b02f2f367b0f2ee1d
4
- data.tar.gz: 2457cc1cf78cfb725b8f35c5c0a4cce01c35896f0a3ed0ac32a19faeb45b0177
3
+ metadata.gz: 2b39f30dc20ead80a6704d27f1a10b9046ad6fe05d164ec4cb31b6606f225a33
4
+ data.tar.gz: 03db26bce85e7f1fad10d2b909284c32fc18f13cd999aa718ddd21d867d29a29
5
5
  SHA512:
6
- metadata.gz: 9cc4d227f2a157b112ae5ae3275062e5ba1b1241d9122c89341859a342d05d558abf4f89bed034a629a5f4f9cda966a47e794f22e9e3fede8e136a758fcd2a1c
7
- data.tar.gz: f513c798461f72270fa247cc927591ae1ec26dd3e0d9606ea7bf81936063fa0026847699f6d233c93505dc891e1111560cbbd7a53d019e0fb033166d58d036a1
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
- ## Install
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
- **Rubygems.org**
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 from_json_file(path, object: Ryo::Object)
26
- from_json File.binread(path), object:
27
- end
28
-
29
- ##
30
- # @param [String] blob
31
- # A blob of JSON.
32
- #
33
- # @param [Ryo] object
34
- # {Ryo::Object Ryo::Object}, or {Ryo::BasicObject Ryo::BasicObject}.
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ryo
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.3"
5
5
  end
@@ -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.from_json_file(path, object:) }
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.2
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-12 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard