ryo.rb 0.5.3 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/specs.yml +2 -2
- data/README.md +30 -14
- data/Rakefile.rb +13 -0
- data/lib/ryo/basic_object.rb +7 -11
- data/lib/ryo/builder.rb +35 -54
- data/lib/ryo/enumerable.rb +62 -79
- data/lib/ryo/object.rb +6 -10
- data/lib/ryo/reflect.rb +55 -155
- data/lib/ryo/utils.rb +68 -0
- data/lib/ryo/version.rb +1 -1
- data/lib/ryo/yaml.rb +45 -0
- data/lib/ryo.rb +24 -37
- data/ryo.rb.gemspec +1 -0
- data/share/ryo.rb/examples/1.0_prototypes_point_object.rb +1 -0
- data/share/ryo.rb/examples/1.1_prototypes_ryo_fn.rb +1 -0
- data/share/ryo.rb/examples/2.0_iteration_each.rb +1 -0
- data/share/ryo.rb/examples/2.1_iteration_map.rb +1 -0
- data/share/ryo.rb/examples/2.2_iteration_ancestors.rb +1 -0
- data/share/ryo.rb/examples/3.0_recursion_ryo_from.rb +1 -0
- data/share/ryo.rb/examples/3.1_recursion_ryo_from_with_array.rb +1 -0
- data/share/ryo.rb/examples/3.2_recursion_ryo_from_with_openstruct.rb +1 -0
- data/share/ryo.rb/examples/4.0_basicobject_ryo_basicobject.rb +1 -0
- data/share/ryo.rb/examples/4.1_basicobject_ryo_basicobject_from.rb +1 -0
- data/share/ryo.rb/examples/5_collisions_resolution_strategy.rb +1 -0
- data/share/ryo.rb/examples/6_beyond_hash_objects.rb +1 -0
- data/share/ryo.rb/examples/7_ryo_memo.rb +1 -0
- data/spec/ryo_enumerable_spec.rb +1 -1
- data/spec/ryo_json_spec.rb +31 -13
- data/spec/ryo_reflect_spec.rb +8 -0
- data/spec/ryo_spec.rb +1 -1
- data/spec/ryo_yaml_spec.rb +44 -0
- metadata +8 -5
- data/.gitlab-ci.yml +0 -9
data/spec/ryo_enumerable_spec.rb
CHANGED
@@ -29,7 +29,7 @@ RSpec.describe Ryo::Enumerable do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context "when verifying the map operation returns a new object" do
|
32
|
-
subject {
|
32
|
+
subject { Module.instance_method(:equal?).bind_call(point_b, point_c) }
|
33
33
|
it { is_expected.to be(false) }
|
34
34
|
end
|
35
35
|
end
|
data/spec/ryo_json_spec.rb
CHANGED
@@ -5,22 +5,40 @@ require "ryo/json"
|
|
5
5
|
require "fileutils"
|
6
6
|
|
7
7
|
RSpec.describe Ryo::JSON do
|
8
|
-
describe ".
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
data/spec/ryo_reflect_spec.rb
CHANGED
@@ -170,6 +170,14 @@ RSpec.describe Ryo::Reflect do
|
|
170
170
|
it { expect(table["point"]["point"]).to be_instance_of(Hash) }
|
171
171
|
it { is_expected.to eq("point" => {"point" => {"x" => 1, "y" => 1}}) }
|
172
172
|
end
|
173
|
+
|
174
|
+
context "when a Ryo object references an Array" do
|
175
|
+
let(:ryo) { Ryo(points: [Ryo(x: 1, y: 1)]) }
|
176
|
+
it { expect(table).to be_instance_of(Hash) }
|
177
|
+
it { expect(table["points"]).to be_instance_of(Array) }
|
178
|
+
it { expect(table["points"][0]).to be_instance_of(Hash) }
|
179
|
+
it { is_expected.to eq("points" => [{"x" => 1, "y" => 1}]) }
|
180
|
+
end
|
173
181
|
end
|
174
182
|
end
|
175
183
|
end
|
data/spec/ryo_spec.rb
CHANGED
@@ -113,7 +113,7 @@ RSpec.describe Ryo do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
context "when verifying the source and duplicate are distinct objects" do
|
116
|
-
subject {
|
116
|
+
subject { Module.instance_method(:equal?).bind_call(point_c, dup) }
|
117
117
|
it { is_expected.to eq(false) }
|
118
118
|
end
|
119
119
|
|
@@ -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.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-13 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
|
@@ -121,7 +121,9 @@ files:
|
|
121
121
|
- lib/ryo/memo.rb
|
122
122
|
- lib/ryo/object.rb
|
123
123
|
- lib/ryo/reflect.rb
|
124
|
+
- lib/ryo/utils.rb
|
124
125
|
- lib/ryo/version.rb
|
126
|
+
- lib/ryo/yaml.rb
|
125
127
|
- ryo.rb.gemspec
|
126
128
|
- share/ryo.rb/examples/1.0_prototypes_point_object.rb
|
127
129
|
- share/ryo.rb/examples/1.1_prototypes_ryo_fn.rb
|
@@ -146,6 +148,7 @@ files:
|
|
146
148
|
- spec/ryo_prototypes_spec.rb
|
147
149
|
- spec/ryo_reflect_spec.rb
|
148
150
|
- spec/ryo_spec.rb
|
151
|
+
- spec/ryo_yaml_spec.rb
|
149
152
|
- spec/setup.rb
|
150
153
|
homepage: https://github.com/0x1eef/ryo.rb#readme
|
151
154
|
licenses:
|
@@ -159,14 +162,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
162
|
requirements:
|
160
163
|
- - ">="
|
161
164
|
- !ruby/object:Gem::Version
|
162
|
-
version: '
|
165
|
+
version: '3.2'
|
163
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
167
|
requirements:
|
165
168
|
- - ">="
|
166
169
|
- !ruby/object:Gem::Version
|
167
170
|
version: '0'
|
168
171
|
requirements: []
|
169
|
-
rubygems_version: 3.5.
|
172
|
+
rubygems_version: 3.5.13
|
170
173
|
signing_key:
|
171
174
|
specification_version: 4
|
172
175
|
summary: Ryo implements prototype-based inheritance, in Ruby
|