y-rb 0.1.0 → 0.1.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: 10cd525c4f285fedd7ea5460790a0515bd15227d49606a8c283b313b9fdd233c
4
- data.tar.gz: 8645608ebd5f936cb3eb11e16a1e8b6fde1874881990b7cd18eb1f1624d5f2af
3
+ metadata.gz: 8640afd442488a57ecdf9c2e84f1f8fb707f533aebdc537a7b6d647635e50000
4
+ data.tar.gz: 173e07d6489afc556269c7740a42c9b741a477b04c10996e6c1a0669e9f51597
5
5
  SHA512:
6
- metadata.gz: 7b36dda334a509d2123430871c47f713852eea552f804db174c2ca2089b6184dacfe6c30641d0693bb4e58897c9659fc99279607498ffe3be44863b369d7080b
7
- data.tar.gz: 3fe5990b463b06da580ada4705e011c84579e5b07eb5565bd15ca80b25a184ef6fac78db423a240521aa9c60313c08ef59e927ef3705897b84b4eacbce97b772
6
+ metadata.gz: 51eb175d76d66ae8401e2f9f7384d2460e9e629a954ca3d8013374f7c89ac9c75f91830ce7286bb1942b0c3106901ed04f3051f37c6255ef1cb928566329864e
7
+ data.tar.gz: 6f426990929b829c1e39054bfbcb373c983e30e56c9de402c7ce8f14f67d5d302666c5fa0b0527b95b8b8ff98fcaedaed28235887ac1050329b6e777f44dec92
data/.rustfmt.toml CHANGED
@@ -61,7 +61,6 @@ use_field_init_shorthand = false
61
61
  force_explicit_abi = true
62
62
  condense_wildcard_suffixes = false
63
63
  color = "Auto"
64
- required_version = "1.4.37"
65
64
  unstable_features = false
66
65
  disable_all_formatting = false
67
66
  skip_children = false
data/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "y-rb"
3
- version = "0.1.0"
4
- authors = ["Hannes Moser <box@hannesmoser.at>"]
3
+ version = "0.1.3"
4
+ authors = ["Hannes Moser <box@hannesmoser.at>", "Hannes Moser <hmoser@gitlab.com>"]
5
5
  edition = "2021"
6
6
  homepage = "https://github.com/y-crdt/yrb"
7
7
  repository = "https://github.com/y-crdt/yrb"
@@ -9,9 +9,17 @@ repository = "https://github.com/y-crdt/yrb"
9
9
  [dependencies]
10
10
  lazy_static = "1.4.0"
11
11
  rutie = "0.8.4"
12
- yrs = "0.7.1"
13
- lib0 = "0.7.1"
14
- cross = "0.2.1"
12
+ yrs = "0.10.1"
13
+ lib0 = "0.10.1" # must match yrs version
14
+
15
+ [target.aarch64-unknown-linux-musl.dependencies]
16
+ rutie = {version="0.8.4", features=["no-link"]}
17
+
18
+ [target.x86_64-unknown-linux-musl.dependencies]
19
+ rutie = {version="0.8.4", features=["no-link"]}
20
+
21
+ [target.aarch64-unknown-linux-gnu.dependencies]
22
+ rutie = {version="0.8.4", features=["no-link"]}
15
23
 
16
24
  [lib]
17
25
  name = "y_rb"
data/Cross.toml CHANGED
@@ -1,2 +1,17 @@
1
1
  [build]
2
- xargo = true
2
+
3
+ [build.dockerfile]
4
+ file = "./build/Dockerfile"
5
+
6
+ [build.env]
7
+ passthrough = [
8
+ "RUBY_VERSION"
9
+ ]
10
+
11
+ [target.aarch64-apple-darwin]
12
+
13
+ [target.x86_64-apple-darwin]
14
+
15
+ [target.x86_64-unknown-linux-gnu]
16
+
17
+ [target.x86_64-unknown-linux-musl]
data/Gemfile CHANGED
@@ -8,6 +8,6 @@ gemspec
8
8
  gem "github-markup"
9
9
  gem "redcarpet"
10
10
  gem "rspec", "~> 3.11.0"
11
- gem "rubocop", "~> 1.21"
12
- gem "rubocop-rspec", "~> 2.10.0"
11
+ gem "rubocop", "~> 1.31"
12
+ gem "rubocop-rspec", "~> 2.12.1"
13
13
  gem "yard"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- y-rb (0.1.0)
4
+ y-rb (0.1.3)
5
5
  rake (~> 13.0)
6
6
  rutie (~> 0.0.4)
7
7
  thermite (~> 0)
@@ -9,17 +9,28 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
+ activesupport (6.1.6.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
12
18
  ast (2.4.2)
19
+ concurrent-ruby (1.1.10)
13
20
  diff-lcs (1.5.0)
14
- github-markup (4.0.0)
21
+ github-markup (4.0.1)
22
+ i18n (1.12.0)
23
+ concurrent-ruby (~> 1.0)
24
+ json (2.6.2)
15
25
  minitar (0.9)
26
+ minitest (5.16.2)
16
27
  parallel (1.22.1)
17
28
  parser (3.1.2.0)
18
29
  ast (~> 2.4.1)
19
30
  rainbow (3.1.1)
20
31
  rake (13.0.6)
21
32
  redcarpet (3.5.1)
22
- regexp_parser (2.3.1)
33
+ regexp_parser (2.5.0)
23
34
  rexml (3.2.5)
24
35
  rspec (3.11.0)
25
36
  rspec-core (~> 3.11.0)
@@ -34,19 +45,20 @@ GEM
34
45
  diff-lcs (>= 1.2.0, < 2.0)
35
46
  rspec-support (~> 3.11.0)
36
47
  rspec-support (3.11.0)
37
- rubocop (1.28.2)
48
+ rubocop (1.31.2)
49
+ json (~> 2.3)
38
50
  parallel (~> 1.10)
39
51
  parser (>= 3.1.0.0)
40
52
  rainbow (>= 2.2.2, < 4.0)
41
53
  regexp_parser (>= 1.8, < 3.0)
42
- rexml
43
- rubocop-ast (>= 1.17.0, < 2.0)
54
+ rexml (>= 3.2.5, < 4.0)
55
+ rubocop-ast (>= 1.18.0, < 2.0)
44
56
  ruby-progressbar (~> 1.7)
45
57
  unicode-display_width (>= 1.4.0, < 3.0)
46
- rubocop-ast (1.17.0)
58
+ rubocop-ast (1.19.1)
47
59
  parser (>= 3.1.1.0)
48
- rubocop-rspec (2.10.0)
49
- rubocop (~> 1.19)
60
+ rubocop-rspec (2.12.1)
61
+ rubocop (~> 1.31)
50
62
  ruby-progressbar (1.11.0)
51
63
  rutie (0.0.4)
52
64
  thermite (0.13.0)
@@ -54,20 +66,26 @@ GEM
54
66
  rake (>= 10)
55
67
  tomlrb (~> 1.2)
56
68
  tomlrb (1.3.0)
57
- unicode-display_width (2.1.0)
69
+ tzinfo (2.0.4)
70
+ concurrent-ruby (~> 1.0)
71
+ unicode-display_width (2.2.0)
58
72
  webrick (1.7.0)
59
- yard (0.9.27)
73
+ yard (0.9.28)
60
74
  webrick (~> 1.7.0)
75
+ zeitwerk (2.6.0)
61
76
 
62
77
  PLATFORMS
63
78
  arm64-darwin-21
79
+ x86_64-linux
64
80
 
65
81
  DEPENDENCIES
82
+ activesupport (~> 6.1.6.1)
66
83
  github-markup
84
+ minitar (~> 0.9)
67
85
  redcarpet
68
86
  rspec (~> 3.11.0)
69
- rubocop (~> 1.21)
70
- rubocop-rspec (~> 2.10.0)
87
+ rubocop (~> 1.31)
88
+ rubocop-rspec (~> 2.12.1)
71
89
  y-rb!
72
90
  yard
73
91
 
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Yrb
2
2
 
3
- > Attention: This gem isn't published yet, but you can play around with it.
4
- > Feedback on the Ruby API is welcome 🙌.
5
-
6
3
  Yrb is a Ruby binding for Y-CRDT. It provides distributed data types that enable
7
4
  real-time collaboration between devices. Yrb can sync data with any other
8
5
  platform that has a Y-CRDT binding, allowing for seamless cross-domain
@@ -27,6 +24,15 @@ Or install it yourself as:
27
24
 
28
25
  $ gem install y-rb
29
26
 
27
+ > **⚠ WARNING: Partial support for pre-built binaries.**
28
+ > `y-rb` comes with experimental pre-built binaries for a few platforms, but it
29
+ > is not possible to support all targets right now. Please make sure there is an
30
+ > archive that matches the OS, CPU architecture, and Ruby version. You can find
31
+ > the assets listed with each [release](https://github.com/y-crdt/yrb/releases).
32
+ >
33
+ > If the platform is not listed, you need to add the latest stable Rust + Cargo
34
+ > to your build dependencies in order for `y-rb` to install properly.
35
+
30
36
  ## Usage
31
37
 
32
38
  ```ruby
@@ -37,7 +43,7 @@ local_text = local.get_text("my text")
37
43
  # add some data to the text structure
38
44
  local_text.push("hello")
39
45
 
40
- # create a remote doccument sharing the same text structure
46
+ # create a remote document sharing the same text structure
41
47
  remote = Y::Doc.new
42
48
  remote_text = remote.get_text("my text")
43
49
 
@@ -54,7 +60,7 @@ remote.sync(update)
54
60
  puts remote_text.to_s == local_text.to_s # true
55
61
  ```
56
62
 
57
- More [examples](./docs/examples).
63
+ More [examples](docs/examples.md).
58
64
 
59
65
  ## Development
60
66
 
@@ -86,7 +92,7 @@ open "http://0.0.0.0:8808/"
86
92
 
87
93
  ## Decision log
88
94
 
89
- For this `gem`, we maintain a [decision log](./docs/decisions.md). Please consult it
95
+ For this `gem`, we maintain a [decision log](docs/decisions.md). Please consult it
90
96
  in case there is some ambiguity in terms of why certain implementation details
91
97
  look as they are.
92
98
 
data/build/Dockerfile ADDED
@@ -0,0 +1,18 @@
1
+ ARG CROSS_BASE_IMAGE
2
+ FROM $CROSS_BASE_IMAGE
3
+
4
+ ENV RUBY_VERSION=3.1.2
5
+
6
+ RUN apt-get update -yq && apt-get install -yq build-essential gnupg2 openssl ruby ruby-dev
7
+ RUN curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
8
+ RUN curl -L https://get.rvm.io | bash -s stable
9
+ RUN /bin/bash -l -c "rvm requirements"
10
+ RUN /bin/bash -l -c "rvm install 3.1.2"
11
+ RUN /bin/bash -l -c "rvm install 3.0.4"
12
+ RUN /bin/bash -l -c "rvm install 2.7.6"
13
+ RUN /bin/bash -l -c "rvm install 2.6.10"
14
+
15
+ COPY build/entrypoint.sh /
16
+ RUN chmod +x "/entrypoint.sh"
17
+
18
+ ENTRYPOINT ["/entrypoint.sh"]
data/build/build.rb ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "active_support/core_ext/string"
5
+ require "fileutils"
6
+ require "minitar"
7
+ require "zlib"
8
+
9
+ require_relative "../lib/y/version"
10
+
11
+ RUBIES = %w[2.6.10 2.7.6 3.0.4 3.1.2].freeze
12
+
13
+ # darwin20 = mac os 11.x
14
+ # darwin21 = mac os 12.x
15
+ # darwin22 = mac os 13.x
16
+ TARGETS = {
17
+ "aarch64-apple-darwin": {
18
+ cpu: "arm64",
19
+ os: "darwin21"
20
+ },
21
+ "aarch64-unknown-linux-gnu": {
22
+ cpu: "arm64",
23
+ os: "linux"
24
+ },
25
+ "aarch64-unknown-linux-musl": {
26
+ cpu: "arm64",
27
+ os: "linux-musl",
28
+ env: {
29
+ "RUSTFLAGS" => "\"-C target-feature=-crt-static\""
30
+ }
31
+ },
32
+ "x86_64-unknown-linux-gnu": {
33
+ cpu: "x86_64",
34
+ os: "linux"
35
+ },
36
+ "x86_64-unknown-linux-musl": {
37
+ cpu: "x86_64",
38
+ os: "linux-musl",
39
+ env: {
40
+ "RUSTFLAGS" => "\"-C target-feature=-crt-static\""
41
+ }
42
+ }
43
+ }.freeze
44
+
45
+ def build_lib(target, options, ruby_version) # rubocop:disable Metrics/MethodLength
46
+ env_vars = if !options.nil? && options.key?(:env)
47
+ target_env = target.to_s.underscore.upcase
48
+ options[:env]
49
+ .map { |env, value| "CARGO_TARGET_#{target_env}_#{env}=#{value}" }
50
+ .join(" ")
51
+ else
52
+ ""
53
+ end
54
+
55
+ cmd = [
56
+ "cargo clean",
57
+ "#{env_vars} RUBY_VERSION=#{ruby_version} cross build --target=#{target} --release"
58
+ ].join(" && ")
59
+
60
+ `#{cmd}`
61
+ end
62
+
63
+ def copy_lib(target)
64
+ path = "#{__dir__}/../target/#{target}/release"
65
+
66
+ file = Dir["#{path}/*{dylib,so}"].first
67
+
68
+ extension = File.extname(file)
69
+ dest = "#{path}/y_rb#{extension}"
70
+
71
+ FileUtils.cp(file, dest)
72
+
73
+ dest
74
+ end
75
+
76
+ # Build
77
+
78
+ FileUtils.rm_rf "#{__dir__}/out"
79
+
80
+ TARGETS.each do |target, options|
81
+ RUBIES.each do |ruby_version|
82
+ puts "Build: target=#{target}, ruby=#{ruby_version}"
83
+
84
+ version = Gem::Version.new(ruby_version)
85
+ version_segments = version.canonical_segments
86
+ ruby_version_string = "#{version_segments[0]}#{version_segments[1]}"
87
+
88
+ build_lib(target, options, ruby_version)
89
+ file = copy_lib(target)
90
+
91
+ raise "Build failed" if file.nil?
92
+
93
+ extension = File.extname(file)
94
+ dir = "#{__dir__}/out/y_rb-#{Y::VERSION}-ruby#{ruby_version_string}-#{options[:os]}-#{options[:cpu]}"
95
+ FileUtils.mkdir_p(dir)
96
+ FileUtils.cp(file, "#{dir}/y_rb#{extension}")
97
+
98
+ archive = "#{dir}/y_rb-#{Y::VERSION}-ruby#{ruby_version_string}-#{options[:os]}-#{options[:cpu]}.tar.gz"
99
+ Zlib::GzipWriter.open(archive) do |tgz|
100
+ Dir.chdir(dir) do
101
+ Archive::Tar::Minitar.pack(".", tgz)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ /bin/bash -l -c "rvm --default use $RUBY_VERSION" && exec "$@"
data/docs/release.md ADDED
@@ -0,0 +1,36 @@
1
+ # Release
2
+
3
+ ## Steps
4
+
5
+ 1. Make sure CI is green
6
+ 2. Update version in `Cargo.toml`
7
+ 3. Update version in `lib/y/version.rb`
8
+ 4. Create a tag matching the version `git tag -a vx.x.x -m "Release version vx.x.x"`
9
+ 5. Push tag to GitHub repo: `git push vx.x.x`
10
+ 6. Create a GitHub release (requires GitHub CLI): `gh release create vx.x.x ./build/out/*/*.gz`
11
+ 7. Package and upload gem: `gem build && gem push y-rb-x.x.x.gem`
12
+
13
+ ## Cross-compile binaries (to be released as assets on GitHub)
14
+
15
+ There is a script in `./build` that automates a fair chunk of work, but it is
16
+ not bulletproof. I mainly use it to compile for arm64 platforms on my machine,
17
+ and then upload manually. Most binaries (especially x86) should come from CI.
18
+
19
+ It also includes a workaround for Alpine (popular in Docker images) what usually
20
+ requires to be a static lib.
21
+
22
+ Run the following script. It produces a bunch of archives in `./build/out/`.
23
+ You need to upload the produced assets manually after the GitHub release was
24
+ created.
25
+
26
+ ```bash
27
+ ./build/build.rb
28
+ ```
29
+
30
+ ## Future work
31
+
32
+ With this [PR](https://github.com/rubygems/rubygems/pull/5175) merged into
33
+ rubygems, we will most likely be able to rely on the extension to manage builds
34
+ for us in the future.
35
+
36
+ Pre-build binaries are not verified, and are inherently a security concern.
data/lib/y/doc.rb CHANGED
@@ -16,6 +16,9 @@ module Y
16
16
  # remote_map = remote.get_map("my_map")
17
17
  # pp remote_map.to_h #=> {hello: "world"}
18
18
  class Doc
19
+ ZERO_STATE = [0].freeze
20
+ private_constant :ZERO_STATE
21
+
19
22
  # Commit current transaction
20
23
  #
21
24
  # This is a convenience method that invokes {Y::Transaction#commit} on the
@@ -42,7 +45,7 @@ module Y
42
45
  #
43
46
  # @param [::Array<Int>] state The state to create the diff against
44
47
  # @return [::Array<Int>] Binary encoded diff
45
- def diff(state)
48
+ def diff(state = ZERO_STATE)
46
49
  ydoc_encode_diff_v1(state)
47
50
  end
48
51
 
data/lib/y/rb.rb CHANGED
@@ -10,7 +10,17 @@ require_relative "version"
10
10
  require_relative "xml"
11
11
 
12
12
  module Y
13
- Rutie.new(:y_rb).init(
13
+ # support pre-built and local built libraries
14
+ lib_path = if Dir.exist?(File.join(__dir__, "..", "..", "target", "release"))
15
+ nil
16
+ else
17
+ File.join(__dir__, "..", "..")
18
+ end
19
+
20
+ Rutie.new(
21
+ :y_rb,
22
+ lib_path: lib_path
23
+ ).init(
14
24
  "Init_yrb",
15
25
  File.join(__dir__, "..")
16
26
  )
data/lib/y/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Y
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.3"
5
5
  end
data/src/lib.rs CHANGED
@@ -23,7 +23,7 @@ pub extern "C" fn Init_yrb() {
23
23
  klass.def_private("yarray_insert", yarray::yarray_insert);
24
24
  klass.def_private(
25
25
  "yarray_insert_range",
26
- yarray::yarray_insert_range,
26
+ yarray::yarray_insert_range
27
27
  );
28
28
  klass.def_private("yarray_length", yarray::yarray_length);
29
29
  klass.def_private("yarray_observe", yarray::yarray_observe);
@@ -32,7 +32,7 @@ pub extern "C" fn Init_yrb() {
32
32
  klass.def_private("yarray_remove", yarray::yarray_remove);
33
33
  klass.def_private(
34
34
  "yarray_remove_range",
35
- yarray::yarray_remove_range,
35
+ yarray::yarray_remove_range
36
36
  );
37
37
  klass.def_private("yarray_to_a", yarray::yarray_to_a);
38
38
  klass.def_private("yarray_unobserve", yarray::yarray_unobserve);
@@ -66,11 +66,11 @@ pub extern "C" fn Init_yrb() {
66
66
  klass.def_private("ytext_insert_embed", ytext::ytext_insert_embed);
67
67
  klass.def_private(
68
68
  "ytext_insert_embed_with_attrs",
69
- ytext::ytext_insert_embed_with_attributes,
69
+ ytext::ytext_insert_embed_with_attributes
70
70
  );
71
71
  klass.def_private(
72
72
  "ytext_insert_with_attrs",
73
- ytext::ytext_insert_with_attributes,
73
+ ytext::ytext_insert_with_attributes
74
74
  );
75
75
  klass.def_private("ytext_remove_range", ytext::ytext_remove_range);
76
76
  klass.def_private("ytext_format", ytext::ytext_format);
@@ -86,35 +86,35 @@ pub extern "C" fn Init_yrb() {
86
86
  .define(|klass| {
87
87
  klass.def_private(
88
88
  "ytransaction_apply_update",
89
- ytransaction::ytransaction_apply_update,
89
+ ytransaction::ytransaction_apply_update
90
90
  );
91
91
  klass.def_private(
92
92
  "ytransaction_commit",
93
- ytransaction::ytransaction_commit,
93
+ ytransaction::ytransaction_commit
94
94
  );
95
95
  klass.def_private(
96
96
  "ytransaction_get_array",
97
- ytransaction::ytransaction_get_array,
97
+ ytransaction::ytransaction_get_array
98
98
  );
99
99
  klass.def_private(
100
100
  "ytransaction_get_map",
101
- ytransaction::ytransaction_get_map,
101
+ ytransaction::ytransaction_get_map
102
102
  );
103
103
  klass.def_private(
104
104
  "ytransaction_get_text",
105
- ytransaction::ytransaction_get_text,
105
+ ytransaction::ytransaction_get_text
106
106
  );
107
107
  klass.def_private(
108
108
  "ytransaction_get_xml_element",
109
- ytransaction::ytransaction_get_xml_element,
109
+ ytransaction::ytransaction_get_xml_element
110
110
  );
111
111
  klass.def_private(
112
112
  "ytransaction_get_xml_text",
113
- ytransaction::ytransaction_get_xml_text,
113
+ ytransaction::ytransaction_get_xml_text
114
114
  );
115
115
  klass.def_private(
116
116
  "ytransaction_state_vector",
117
- ytransaction::ytransaction_state_vector,
117
+ ytransaction::ytransaction_state_vector
118
118
  );
119
119
  });
120
120
 
@@ -123,123 +123,123 @@ pub extern "C" fn Init_yrb() {
123
123
  .define(|klass| {
124
124
  klass.def_private(
125
125
  "yxml_element_attributes",
126
- yxml::yxml_element_attributes,
126
+ yxml::yxml_element_attributes
127
127
  );
128
128
  klass.def_private(
129
129
  "yxml_element_first_child",
130
- yxml::yxml_element_first_child,
130
+ yxml::yxml_element_first_child
131
131
  );
132
132
  klass.def_private("yxml_element_get", yxml::yxml_element_get);
133
133
  klass.def_private(
134
134
  "yxml_element_get_attribute",
135
- yxml::yxml_element_get_attribute,
135
+ yxml::yxml_element_get_attribute
136
136
  );
137
137
  klass.def_private(
138
138
  "yxml_element_insert_attribute",
139
- yxml::yxml_element_insert_attribute,
139
+ yxml::yxml_element_insert_attribute
140
140
  );
141
141
  klass.def_private(
142
142
  "yxml_element_insert_element",
143
- yxml::yxml_element_insert_element,
143
+ yxml::yxml_element_insert_element
144
144
  );
145
145
  klass.def_private(
146
146
  "yxml_element_insert_text",
147
- yxml::yxml_element_insert_text,
147
+ yxml::yxml_element_insert_text
148
148
  );
149
149
  klass.def_private(
150
150
  "yxml_element_next_sibling",
151
- yxml::yxml_element_next_sibling,
151
+ yxml::yxml_element_next_sibling
152
152
  );
153
153
  klass.def_private(
154
154
  "yxml_element_observe",
155
- yxml::yxml_element_observe,
155
+ yxml::yxml_element_observe
156
156
  );
157
157
  klass.def_private(
158
158
  "yxml_element_parent",
159
- yxml::yxml_element_parent,
159
+ yxml::yxml_element_parent
160
160
  );
161
161
  klass.def_private(
162
162
  "yxml_element_prev_sibling",
163
- yxml::yxml_element_prev_sibling,
163
+ yxml::yxml_element_prev_sibling
164
164
  );
165
165
  klass.def_private(
166
166
  "yxml_element_push_elem_back",
167
- yxml::yxml_element_push_elem_back,
167
+ yxml::yxml_element_push_elem_back
168
168
  );
169
169
  klass.def_private(
170
170
  "yxml_element_push_elem_front",
171
- yxml::yxml_element_push_elem_front,
171
+ yxml::yxml_element_push_elem_front
172
172
  );
173
173
  klass.def_private(
174
174
  "yxml_element_push_text_back",
175
- yxml::yxml_element_push_text_back,
175
+ yxml::yxml_element_push_text_back
176
176
  );
177
177
  klass.def_private(
178
178
  "yxml_element_push_text_front",
179
- yxml::yxml_element_push_text_front,
179
+ yxml::yxml_element_push_text_front
180
180
  );
181
181
  klass.def_private(
182
182
  "yxml_element_remove_attribute",
183
- yxml::yxml_element_remove_attribute,
183
+ yxml::yxml_element_remove_attribute
184
184
  );
185
185
  klass.def_private(
186
186
  "yxml_element_remove_range",
187
- yxml::yxml_element_remove_range,
187
+ yxml::yxml_element_remove_range
188
188
  );
189
189
  klass.def_private("yxml_element_size", yxml::yxml_element_size);
190
190
  klass.def_private("yxml_element_tag", yxml::yxml_element_tag);
191
191
  klass.def_private(
192
192
  "yxml_element_to_s",
193
- yxml::yxml_element_to_string,
193
+ yxml::yxml_element_to_string
194
194
  );
195
195
  klass.def_private(
196
196
  "yxml_element_unobserve",
197
- yxml::yxml_element_unobserve,
197
+ yxml::yxml_element_unobserve
198
198
  );
199
199
  });
200
200
 
201
201
  module.define_nested_class("XMLText", None).define(|klass| {
202
202
  klass.def_private(
203
203
  "yxml_text_attributes",
204
- yxml::yxml_text_attributes,
204
+ yxml::yxml_text_attributes
205
205
  );
206
206
  klass.def_private("yxml_text_format", yxml::yxml_text_format);
207
207
  klass.def_private(
208
208
  "yxml_text_get_attribute",
209
- yxml::yxml_text_get_attribute,
209
+ yxml::yxml_text_get_attribute
210
210
  );
211
211
  klass.def_private("yxml_text_insert", yxml::yxml_text_insert);
212
212
  klass.def_private(
213
213
  "yxml_text_insert_attribute",
214
- yxml::yxml_text_insert_attribute,
214
+ yxml::yxml_text_insert_attribute
215
215
  );
216
216
  klass.def_private(
217
217
  "yxml_text_insert_embed",
218
- yxml::yxml_text_insert_embed,
218
+ yxml::yxml_text_insert_embed
219
219
  );
220
220
  klass.def_private(
221
221
  "yxml_text_insert_embed_with_attrs",
222
- yxml::yxml_text_insert_embed_with_attributes,
222
+ yxml::yxml_text_insert_embed_with_attributes
223
223
  );
224
224
  klass.def_private(
225
225
  "yxml_text_insert_with_attrs",
226
- yxml::yxml_text_insert_with_attributes,
226
+ yxml::yxml_text_insert_with_attributes
227
227
  );
228
228
  klass.def_private("yxml_text_length", yxml::yxml_text_length);
229
229
  klass.def_private(
230
230
  "yxml_text_next_sibling",
231
- yxml::yxml_text_next_sibling,
231
+ yxml::yxml_text_next_sibling
232
232
  );
233
233
  klass.def_private("yxml_text_observe", yxml::yxml_text_observe);
234
234
  klass.def_private("yxml_text_parent", yxml::yxml_text_parent);
235
235
  klass.def_private(
236
236
  "yxml_text_prev_sibling",
237
- yxml::yxml_text_prev_sibling,
237
+ yxml::yxml_text_prev_sibling
238
238
  );
239
239
  klass.def_private("yxml_text_push", yxml::yxml_text_push);
240
240
  klass.def_private(
241
241
  "yxml_text_remove_range",
242
- yxml::yxml_text_remove_range,
242
+ yxml::yxml_text_remove_range
243
243
  );
244
244
  klass.def_private("yxml_text_to_s", yxml::yxml_text_to_string);
245
245
  klass.def_private("yxml_text_unobserve", yxml::yxml_text_unobserve);
data/src/util.rs CHANGED
@@ -4,7 +4,7 @@ use crate::yxml::{XML_ELEMENT_WRAPPER, XML_TEXT_WRAPPER};
4
4
  use lib0::any::Any;
5
5
  use rutie::{
6
6
  AnyException, AnyObject, Array, Boolean, Exception, Fixnum, Float, Hash,
7
- Integer, Module, NilClass, Object, RString, Symbol,
7
+ Integer, Module, NilClass, Object, RString, Symbol
8
8
  };
9
9
  use std::borrow::Borrow;
10
10
  use std::collections::HashMap;
@@ -49,14 +49,12 @@ pub(crate) fn map_any_type_to_ruby(input: &Any) -> AnyObject {
49
49
  let key = Symbol::new(k.as_ref());
50
50
  let val = map_any_type_to_ruby(v);
51
51
  h.store(key, val);
52
- ()
53
52
  });
54
53
  h.to_any_object()
55
54
  }
56
55
  }
57
56
  }
58
57
 
59
- // This function gets reported as unused.
60
58
  pub(crate) fn map_yrs_value_to_ruby(value: Value) -> AnyObject {
61
59
  match value {
62
60
  Value::Any(v) => map_any_type_to_ruby(v.borrow()),
@@ -75,12 +73,12 @@ pub(crate) fn map_yrs_value_to_ruby(value: Value) -> AnyObject {
75
73
  .wrap_data(x, &*XML_ELEMENT_WRAPPER),
76
74
  Value::YXmlText(x) => Module::from_existing("Y")
77
75
  .get_nested_class("XMLText")
78
- .wrap_data(x, &*XML_TEXT_WRAPPER),
76
+ .wrap_data(x, &*XML_TEXT_WRAPPER)
79
77
  }
80
78
  }
81
79
 
82
80
  pub(crate) fn map_ruby_type_to_rust(
83
- input: AnyObject,
81
+ input: AnyObject
84
82
  ) -> Result<Any, AnyException> {
85
83
  if let Ok(_v) = input.try_convert_to::<NilClass>() {
86
84
  return Ok(Any::Null);
@@ -107,7 +105,7 @@ pub(crate) fn map_ruby_type_to_rust(
107
105
 
108
106
  Err(AnyException::new(
109
107
  "TypeError",
110
- Some("cannot map input type"),
108
+ Some("cannot map input type")
111
109
  ))
112
110
  }
113
111
 
data/src/yarray.rs CHANGED
@@ -2,7 +2,7 @@ use crate::util::{map_ruby_type_to_rust, map_yrs_value_to_ruby};
2
2
  use crate::ytransaction::{YTransaction, TRANSACTION_WRAPPER};
3
3
  use rutie::{
4
4
  AnyObject, Array as RArray, Fixnum, Hash, Integer, NilClass, Object, Proc,
5
- Symbol, VM,
5
+ Symbol, VM
6
6
  };
7
7
  use yrs::types::{Change, Value};
8
8
  use yrs::{Array, SubscriptionId};
data/src/ydoc.rs CHANGED
@@ -26,10 +26,16 @@ methods!(
26
26
  let mut doc: &Doc = rtself.get_data_mut(&*DOC_WRAPPER);
27
27
  let state_vector_encoded: Vec<u8> =
28
28
  convert_array_to_vecu8(state_vector.unwrap());
29
- let sv = &StateVector::decode_v1(state_vector_encoded.as_slice());
30
29
 
31
- let update = doc.encode_state_as_update_v1(sv);
30
+ let result = &StateVector::decode_v1(state_vector_encoded.as_slice());
31
+ let sv = match result {
32
+ Ok(sv) => sv,
33
+ Err(error) => {
34
+ panic!("decoding the state vector failed: {:?}", error)
35
+ }
36
+ };
32
37
 
38
+ let update = doc.encode_state_as_update_v1(sv);
33
39
  convert_vecu8_to_array(update)
34
40
  }
35
41
  );
data/src/ymap.rs CHANGED
@@ -3,7 +3,7 @@ use crate::ytransaction::{YTransaction, TRANSACTION_WRAPPER};
3
3
  use lib0::any::Any;
4
4
  use rutie::{
5
5
  AnyObject, Array, Boolean, Class, Fixnum, Hash, Integer, NilClass, Object,
6
- Proc, RString, Symbol, VM,
6
+ Proc, RString, Symbol, VM
7
7
  };
8
8
  use std::rc::Rc;
9
9
  use yrs::types::EntryChange;
data/src/ytext.rs CHANGED
@@ -1,11 +1,11 @@
1
1
  use crate::util::{
2
2
  map_attrs_to_hash, map_hash_to_attrs, map_ruby_type_to_rust,
3
- map_yrs_value_to_ruby,
3
+ map_yrs_value_to_ruby
4
4
  };
5
5
  use crate::ytransaction::{YTransaction, TRANSACTION_WRAPPER};
6
6
  use rutie::{
7
7
  AnyObject, Fixnum, Hash, Integer, NilClass, Object, Proc, RString, Symbol,
8
- VM,
8
+ VM
9
9
  };
10
10
  use yrs::types::Delta;
11
11
  use yrs::{SubscriptionId, Text};
data/src/ytransaction.rs CHANGED
@@ -31,7 +31,8 @@ methods!(
31
31
  let u = convert_array_to_vecu8(update.unwrap());
32
32
 
33
33
  let transaction = rtself.get_data_mut(&*TRANSACTION_WRAPPER);
34
- transaction.apply_update(Update::decode_v1(u.as_slice()));
34
+ let update = Update::decode_v1(u.as_slice()).unwrap();
35
+ transaction.apply_update(update);
35
36
 
36
37
  NilClass::new()
37
38
  },
data/src/yxml.rs CHANGED
@@ -1,11 +1,11 @@
1
1
  use crate::util::{
2
2
  map_attrs_to_hash, map_hash_to_attrs, map_ruby_type_to_rust,
3
- map_yrs_value_to_ruby,
3
+ map_yrs_value_to_ruby
4
4
  };
5
5
  use crate::ytransaction::{YTransaction, TRANSACTION_WRAPPER};
6
6
  use rutie::{
7
7
  AnyObject, Array as RArray, Fixnum, Hash, Integer, Module, NilClass,
8
- Object, Proc, RString, Symbol, VM,
8
+ Object, Proc, RString, Symbol, VM
9
9
  };
10
10
  use yrs::types::xml::Attributes;
11
11
  use yrs::types::{Change, Delta};
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannes Moser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-24 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,7 +52,35 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Yrs "wires" is a Rust port of the Yjs framework.
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.1.6.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.1.6.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: Ruby bindings for yrs. Yrs "wires" is a Rust port of the Yjs framework.
56
84
  email:
57
85
  - hmoser@gitlab.com
58
86
  - box@hannesmoser.at
@@ -61,7 +89,6 @@ extensions:
61
89
  - ext/Rakefile
62
90
  extra_rdoc_files: []
63
91
  files:
64
- - ".cargo/config.toml"
65
92
  - ".dockerignore"
66
93
  - ".editorconfig"
67
94
  - ".rspec"
@@ -77,9 +104,12 @@ files:
77
104
  - Rakefile
78
105
  - bin/console
79
106
  - bin/setup
80
- - docs/build.md
107
+ - build/Dockerfile
108
+ - build/build.rb
109
+ - build/entrypoint.sh
81
110
  - docs/decisions.md
82
111
  - docs/examples.md
112
+ - docs/release.md
83
113
  - ext/Rakefile
84
114
  - lib/y.rb
85
115
  - lib/y/array.rb
@@ -90,7 +120,6 @@ files:
90
120
  - lib/y/transaction.rb
91
121
  - lib/y/version.rb
92
122
  - lib/y/xml.rb
93
- - lib/y_rb.so
94
123
  - src/lib.rs
95
124
  - src/util.rs
96
125
  - src/yarray.rs
@@ -99,14 +128,14 @@ files:
99
128
  - src/ytext.rs
100
129
  - src/ytransaction.rs
101
130
  - src/yxml.rs
102
- homepage: https://about.gitlab.com
131
+ homepage: https://github.com/y-crdt/yrb
103
132
  licenses:
104
133
  - MIT
105
134
  metadata:
106
135
  allowed_push_host: https://rubygems.org
107
- homepage_uri: https://about.gitlab.com
108
- source_code_uri: https://gitlab.com/gitlab-org/incubation-engineering/real-time-editing/y-rb
109
- changelog_uri: https://gitlab.com/gitlab-org/incubation-engineering/real-time-editing/y-rb
136
+ homepage_uri: https://github.com/y-crdt/yrb
137
+ source_code_uri: https://github.com/y-crdt/yrb
138
+ documentation_uri: https://y-crdt.github.io/yrb/
110
139
  rubygems_mfa_required: 'true'
111
140
  post_install_message:
112
141
  rdoc_options: []
data/.cargo/config.toml DELETED
@@ -1,5 +0,0 @@
1
- [target.x86_64-apple-darwin]
2
- linker = "x86_64-apple-darwin14-clang"
3
- ar = "x86_64-apple-darwin14-ar"
4
-
5
- [target.aarch64-apple-darwin]
data/docs/build.md DELETED
@@ -1 +0,0 @@
1
- # Build Instructions
data/lib/y_rb.so DELETED
Binary file