ryo.rb 0.5.2 → 0.5.5

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: c611c0e990fe0cdfd09ede551e1b457e93af7765de379d64b5dbdf6495e2b766
4
+ data.tar.gz: 24406b552991b2459da63847ff4b65071eb2e03cd846956e4a030f506fd5b908
5
5
  SHA512:
6
- metadata.gz: 9cc4d227f2a157b112ae5ae3275062e5ba1b1241d9122c89341859a342d05d558abf4f89bed034a629a5f4f9cda966a47e794f22e9e3fede8e136a758fcd2a1c
7
- data.tar.gz: f513c798461f72270fa247cc927591ae1ec26dd3e0d9606ea7bf81936063fa0026847699f6d233c93505dc891e1111560cbbd7a53d019e0fb033166d58d036a1
6
+ metadata.gz: 28dca6bc48b5aab85c3e08698a60e460142114623b3f914db25bbe83fa767cdd70bcb8bb4bf68d07188cc884840d696cbba81b96683d10a690d939979e0f5dfc
7
+ data.tar.gz: 325e58af48dc0cc6e85344ecedc006b6b331a2011432bc76069c374288bd676d2d918eee9807ee0194e8d2e31c0fe1dcbeda38b9c6a0f8982a1ea26ca0588457
@@ -12,7 +12,7 @@ jobs:
12
12
  fail-fast: false
13
13
  matrix:
14
14
  os: [ubuntu-latest]
15
- ruby: [3.1, 3.2, 3.3]
15
+ ruby: [3.2, 3.3]
16
16
  runs-on: ${{ matrix.os }}
17
17
  steps:
18
18
  - uses: actions/checkout@v2
@@ -20,4 +20,4 @@ jobs:
20
20
  with:
21
21
  ruby-version: ${{ matrix.ruby }}
22
22
  - run: bundle install
23
- - run: bundle exec rspec
23
+ - run: rake ci
data/README.md CHANGED
@@ -301,17 +301,16 @@ p ryo.then { 34 } # => 34
301
301
  #### Duck typing
302
302
 
303
303
  The documentation has used simple terms to describe the objects that Ryo works
304
- with: Hash and Array objects. But in reality, Ryo uses duck typing, so any object
305
- that implements `#each_pair` can be treated as a Hash object, and any object that
306
- implements `#each` can be treated as an Array object. Note that only
304
+ with: Hash and Array objects. But that doesn't quite capture the fact that Ryo
305
+ uses duck typing: any object that implements `#each_pair` is similar to a Hash,
306
+ and any object that implements `#each` is similar to an Array. Note that only
307
307
  [Ryo.from](https://0x1eef.github.io/x/ryo.rb/Ryo.html#from-class_method),
308
308
  [Ryo::Object.from](https://0x1eef.github.io/x/ryo.rb/Ryo/Object.html#from-class_method)
309
309
  and
310
310
  [Ryo::BasicObject.from](https://0x1eef.github.io/x/ryo.rb/Ryo/BasicObject.html#from-class_method)
311
- can handle Array/#each objects.
311
+ can handle Array-like objects.
312
312
 
313
- Here's an example of how to turn your own custom object, which implements
314
- `#each_pair`, into a Ryo object:
313
+ The following example implements `#each_pair`:
315
314
 
316
315
  ``` ruby
317
316
  require "ryo"
@@ -333,9 +332,12 @@ p point.x # => 5
333
332
  p point.y # => 10
334
333
  ```
335
334
 
336
- ## Install
335
+ ## Documentation
336
+
337
+ A complete API reference is available at
338
+ [0x1eef.github.io/x/ryo.rb](https://0x1eef.github.io/x/ryo.rb)
337
339
 
338
- **Rubygems.org**
340
+ ## Install
339
341
 
340
342
  Ryo can be installed via rubygems.org:
341
343
 
@@ -350,7 +352,7 @@ Ryo can be installed via rubygems.org:
350
352
 
351
353
  Thanks to
352
354
  [@awfulcooking (mooff)](https://github.com/awfulcooking)
353
- for the helpful discussions, ideas, and advice
355
+ for the helpful discussions
354
356
 
355
357
  ## License
356
358
 
data/Rakefile.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+
3
+ desc "Run CI tasks"
4
+ task :ci do
5
+ sh "bundle exec rubocop"
6
+ sh "bundle exec rspec spec/"
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :test do
11
+ sh "bundle exec rspec spec/"
12
+ end
13
+ task default: :test
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/reflect.rb CHANGED
@@ -220,9 +220,9 @@ module Ryo::Reflect
220
220
  #
221
221
  # @return [::Object, ::BasicObject]
222
222
  # Returns the return value of the method call.
223
- def call_method(ryo, method, *args, &b)
223
+ def call_method(ryo, method, *, &b)
224
224
  kernel(:__send__)
225
- .bind_call(ryo, method, *args, &b)
225
+ .bind_call(ryo, method, *, &b)
226
226
  end
227
227
 
228
228
  ##
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.5"
5
5
  end
data/lib/ryo/yaml.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # The {Ryo::YAML Ryo::YAML} module provides a number of methods
5
+ # for coercing YAML data into a Ryo object. It must be required
6
+ # separately to Ryo (ie: require "ryo/yaml"), and the methods of
7
+ # this module are then available on the {Ryo Ryo} module.
8
+ module Ryo::YAML
9
+ require "yaml"
10
+ extend self
11
+
12
+ ##
13
+ # @example
14
+ # Ryo.from_yaml(path: "/foo/bar/baz.yaml")
15
+ # Ryo.from_yaml(string: "---\nfoo: bar\n")
16
+ #
17
+ # @param [String] path
18
+ # The path to a YAML file
19
+ #
20
+ # @param [String] string
21
+ # A blob of YAML
22
+ #
23
+ # @param [Ryo] object
24
+ # {Ryo::Object Ryo::Object}, or {Ryo::BasicObject Ryo::BasicObject}
25
+ # Defaults to {Ryo::Object Ryo::Object}
26
+ #
27
+ # @raise [SystemCallError]
28
+ # Might raise a number of Errno exceptions
29
+ #
30
+ # @return [Ryo::Object, Ryo::BasicObject]
31
+ # Returns a Ryo object
32
+ def from_yaml(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 YAML.load_file(path)
37
+ elsif string
38
+ object.from YAML.load(string)
39
+ else
40
+ raise ArgumentError, "No path or string provided"
41
+ end
42
+ end
43
+
44
+ Ryo.extend(self)
45
+ end
data/ryo.rb.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.require_paths = ["lib"]
13
13
  gem.description = "Ryo implements prototype-based inheritance, in Ruby"
14
14
  gem.summary = gem.description
15
+ gem.required_ruby_version = ">= 3.2"
15
16
  gem.add_development_dependency "yard", "~> 0.9"
16
17
  gem.add_development_dependency "redcarpet", "~> 3.5"
17
18
  gem.add_development_dependency "rspec", "~> 3.10"
@@ -5,22 +5,40 @@ require "ryo/json"
5
5
  require "fileutils"
6
6
 
7
7
  RSpec.describe Ryo::JSON do
8
- describe ".from_json_file" do
9
- subject(:ryo) { described_class.from_json_file(path, object:) }
10
- before { File.binwrite path, JSON.dump(x: 20, y: 40) }
11
- after { FileUtils.rm(path) }
12
- let(:path) { File.join(__dir__, "test.json") }
8
+ describe ".from_json" do
9
+ context "with a path" do
10
+ subject(:ryo) { described_class.from_json(path:, object:) }
11
+ before { File.binwrite path, JSON.dump(x: 20, y: 40) }
12
+ after { FileUtils.rm(path) }
13
+ let(:path) { File.join(__dir__, "test.json") }
13
14
 
14
- context "with Ryo::Object" do
15
- let(:object) { Ryo::Object }
16
- it { is_expected.to be_instance_of(Ryo::Object) }
17
- it { is_expected.to eq("x" => 20, "y" => 40) }
15
+ context "with Ryo::Object" do
16
+ let(:object) { Ryo::Object }
17
+ it { is_expected.to be_instance_of(Ryo::Object) }
18
+ it { is_expected.to eq("x" => 20, "y" => 40) }
19
+ end
20
+
21
+ context "with Ryo::BasicObject" do
22
+ let(:object) { Ryo::BasicObject }
23
+ it { expect(Ryo::BasicObject === ryo).to be(true) }
24
+ it { is_expected.to eq("x" => 20, "y" => 40) }
25
+ end
18
26
  end
19
27
 
20
- context "with Ryo::BasicObject" do
21
- let(:object) { Ryo::BasicObject }
22
- it { expect(Ryo::BasicObject === ryo).to be(true) }
23
- it { is_expected.to eq("x" => 20, "y" => 40) }
28
+ context "with a string" do
29
+ subject(:ryo) { described_class.from_json(string: "{\"x\": 20, \"y\": 40}", object:) }
30
+
31
+ context "with Ryo::Object" do
32
+ let(:object) { Ryo::Object }
33
+ it { is_expected.to be_instance_of(Ryo::Object) }
34
+ it { is_expected.to eq("x" => 20, "y" => 40) }
35
+ end
36
+
37
+ context "with Ryo::BasicObject" do
38
+ let(:object) { Ryo::BasicObject }
39
+ it { expect(Ryo::BasicObject === ryo).to be(true) }
40
+ it { is_expected.to eq("x" => 20, "y" => 40) }
41
+ end
24
42
  end
25
43
  end
26
44
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "setup"
4
+ require "ryo/yaml"
5
+ require "fileutils"
6
+
7
+ RSpec.describe Ryo::YAML do
8
+ describe ".from_yaml" do
9
+ context "with a path" do
10
+ subject(:ryo) { described_class.from_yaml(path:, object:) }
11
+ before { File.binwrite path, YAML.dump(x: 20, y: 40) }
12
+ after { FileUtils.rm(path) }
13
+ let(:path) { File.join(__dir__, "test.yaml") }
14
+
15
+ context "with Ryo::Object" do
16
+ let(:object) { Ryo::Object }
17
+ it { is_expected.to be_instance_of(Ryo::Object) }
18
+ it { is_expected.to eq("x" => 20, "y" => 40) }
19
+ end
20
+
21
+ context "with Ryo::BasicObject" do
22
+ let(:object) { Ryo::BasicObject }
23
+ it { expect(Ryo::BasicObject === ryo).to be(true) }
24
+ it { is_expected.to eq("x" => 20, "y" => 40) }
25
+ end
26
+ end
27
+
28
+ context "with a string" do
29
+ subject(:ryo) { described_class.from_yaml(string: "---\nx: 20\ny: 40\n", object:) }
30
+
31
+ context "with Ryo::Object" do
32
+ let(:object) { Ryo::Object }
33
+ it { is_expected.to be_instance_of(Ryo::Object) }
34
+ it { is_expected.to eq("x" => 20, "y" => 40) }
35
+ end
36
+
37
+ context "with Ryo::BasicObject" do
38
+ let(:object) { Ryo::BasicObject }
39
+ it { expect(Ryo::BasicObject === ryo).to be(true) }
40
+ it { is_expected.to eq("x" => 20, "y" => 40) }
41
+ end
42
+ end
43
+ end
44
+ end
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.5
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-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -104,13 +104,13 @@ files:
104
104
  - ".bundle/config"
105
105
  - ".github/workflows/specs.yml"
106
106
  - ".gitignore"
107
- - ".gitlab-ci.yml"
108
107
  - ".projectile"
109
108
  - ".rubocop.yml"
110
109
  - ".yardopts"
111
110
  - Gemfile
112
111
  - LICENSE
113
112
  - README.md
113
+ - Rakefile.rb
114
114
  - lib/ryo.rb
115
115
  - lib/ryo/basic_object.rb
116
116
  - lib/ryo/builder.rb
@@ -122,6 +122,7 @@ files:
122
122
  - lib/ryo/object.rb
123
123
  - lib/ryo/reflect.rb
124
124
  - lib/ryo/version.rb
125
+ - lib/ryo/yaml.rb
125
126
  - ryo.rb.gemspec
126
127
  - share/ryo.rb/examples/1.0_prototypes_point_object.rb
127
128
  - share/ryo.rb/examples/1.1_prototypes_ryo_fn.rb
@@ -146,6 +147,7 @@ files:
146
147
  - spec/ryo_prototypes_spec.rb
147
148
  - spec/ryo_reflect_spec.rb
148
149
  - spec/ryo_spec.rb
150
+ - spec/ryo_yaml_spec.rb
149
151
  - spec/setup.rb
150
152
  homepage: https://github.com/0x1eef/ryo.rb#readme
151
153
  licenses:
@@ -159,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
161
  requirements:
160
162
  - - ">="
161
163
  - !ruby/object:Gem::Version
162
- version: '0'
164
+ version: '3.2'
163
165
  required_rubygems_version: !ruby/object:Gem::Requirement
164
166
  requirements:
165
167
  - - ">="
data/.gitlab-ci.yml DELETED
@@ -1,9 +0,0 @@
1
- stages:
2
- - test
3
-
4
- test-ruby32:
5
- stage: test
6
- image: ruby:3.2.1
7
- script:
8
- - bundle install
9
- - bundle exec rspec spec/