yrby 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -0
- data/Cargo.lock +12 -20
- data/README.md +57 -6
- data/ext/yrby/Cargo.toml +1 -1
- data/ext/yrby/src/array.rs +37 -25
- data/ext/yrby/src/lib.rs +161 -99
- data/ext/yrby/src/map.rs +26 -15
- data/ext/yrby/src/read.rs +76 -1
- data/ext/yrby/src/shared.rs +29 -10
- data/ext/yrby/src/text.rs +14 -17
- data/ext/yrby/src/xml_text.rs +46 -55
- data/lib/generators/yrby/install/install_generator.rb +39 -3
- data/lib/y/array.rb +17 -0
- data/lib/y/collaborative/attribute.rb +10 -9
- data/lib/y/collaborative/helper.rb +4 -4
- data/lib/y/collaborative.rb +6 -5
- data/lib/y/doc.rb +52 -9
- data/lib/y/map.rb +12 -0
- data/lib/y/trix.rb +393 -0
- data/lib/y/version.rb +1 -1
- data/lib/y.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e9fdbe6f55b4ac9abdaf26e68608f61149cd0d046c03cff98fafdd8a0a2e1875
|
|
4
|
+
data.tar.gz: 91435b79e9da914585963fc108e71c90a8400d3433705fdea2d65433dab7fba4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 30424070ae156ecd2ee8ef295cd90b69c4b887f0732fa833993dad5ddb904c64a8b97f8be89a32309e0f4095e58ee0e9f39870ac2fae4d089cc8b9e889d2330b
|
|
7
|
+
data.tar.gz: 9a3a67132eef81c7ac24821ecf55df7929484bc48363f2ca263e435c16db6a00854f442085734896fff1d66d60df484cc5c9db55f8daebe6a1b46af51e4be3a1
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,52 @@ to follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.10.0] - 2026-11-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `Y::Doc#read_text_delta(name)` reads a `Y.Text` root with its formatting:
|
|
14
|
+
the runs of text with their attributes, and the embeds, as a JSON array
|
|
15
|
+
string. It is what `ytext.toDelta()` returns in JavaScript. `read_text`
|
|
16
|
+
gives the characters alone, which is not enough for an editor that keeps
|
|
17
|
+
rich text in a plain `Y.Text` (Quill, or Trix through y-trix).
|
|
18
|
+
|
|
19
|
+
- `Y::Trix` renders a Trix document shared with the
|
|
20
|
+
[y-trix](https://github.com/jpcamara/y-trix) binding to the HTML Trix
|
|
21
|
+
saves: `Y::Trix.new(doc).to_html`. Blocks and how they nest, text
|
|
22
|
+
attributes, links, line breaks, Trix's handling of spaces, right to left
|
|
23
|
+
text and attachments come out as Trix writes them, checked against
|
|
24
|
+
documents captured from real editors. Content from the document is
|
|
25
|
+
escaped and filtered, and the HTML of a content attachment is left out
|
|
26
|
+
unless `content:` says how to make it safe.
|
|
27
|
+
|
|
28
|
+
## [0.9.1] - 2026-11-08
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- yrby builds against yrs 0.28.1. An insert into a text no longer recounts
|
|
33
|
+
the UTF-16 length of each string before it, so appending to a long text
|
|
34
|
+
costs about the same at any length: 80k one-character appends took 2.5 s
|
|
35
|
+
and now take 48 ms.
|
|
36
|
+
|
|
37
|
+
### Experimental
|
|
38
|
+
|
|
39
|
+
- `Y::Doc#edit` returns the document's own writes and never a peer's. The
|
|
40
|
+
document keeps the update of every local transaction until an edit returns
|
|
41
|
+
it, merged into one, so a write made outside an edit, from another thread
|
|
42
|
+
or fiber, or in a block that raised comes with the next edit. Before this,
|
|
43
|
+
the edit returned everything the document gained while the block ran, so
|
|
44
|
+
an update applied from a peer meanwhile was sent again as the edit's own,
|
|
45
|
+
and a caller had to lock the document to keep them apart. Each edit takes
|
|
46
|
+
everything unsent at once, so the updates edits return have no gaps
|
|
47
|
+
between them. A peer's update doesn't wait for an edit.
|
|
48
|
+
|
|
49
|
+
- `Y::Map#set_text(key, content = "")` stores a new `Y.Text` at a key and
|
|
50
|
+
returns its live `Y::Text`. `Y::Array#push_text(content = "")` and
|
|
51
|
+
`#insert_text(index, content = "")` do the same in a list. Before this,
|
|
52
|
+
Ruby could edit a nested `Y.Text` a browser made but couldn't make one,
|
|
53
|
+
so a server couldn't set up a form whose fields merge typing.
|
|
54
|
+
|
|
9
55
|
## yrby-client 0.7.1 - 2026-11-03
|
|
10
56
|
|
|
11
57
|
### Fixed
|
data/Cargo.lock
CHANGED
|
@@ -44,16 +44,14 @@ dependencies = [
|
|
|
44
44
|
|
|
45
45
|
[[package]]
|
|
46
46
|
name = "bindgen"
|
|
47
|
-
version = "0.
|
|
47
|
+
version = "0.72.1"
|
|
48
48
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
49
|
-
checksum = "
|
|
49
|
+
checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
|
|
50
50
|
dependencies = [
|
|
51
51
|
"bitflags",
|
|
52
52
|
"cexpr",
|
|
53
53
|
"clang-sys",
|
|
54
54
|
"itertools",
|
|
55
|
-
"lazy_static",
|
|
56
|
-
"lazycell",
|
|
57
55
|
"proc-macro2",
|
|
58
56
|
"quote",
|
|
59
57
|
"regex",
|
|
@@ -221,12 +219,6 @@ version = "1.5.0"
|
|
|
221
219
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
222
220
|
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|
223
221
|
|
|
224
|
-
[[package]]
|
|
225
|
-
name = "lazycell"
|
|
226
|
-
version = "1.3.0"
|
|
227
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
228
|
-
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|
229
|
-
|
|
230
222
|
[[package]]
|
|
231
223
|
name = "lexical-yjs-html"
|
|
232
224
|
version = "0.2.1"
|
|
@@ -366,18 +358,18 @@ dependencies = [
|
|
|
366
358
|
|
|
367
359
|
[[package]]
|
|
368
360
|
name = "rb-sys"
|
|
369
|
-
version = "0.9.
|
|
361
|
+
version = "0.9.130"
|
|
370
362
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
371
|
-
checksum = "
|
|
363
|
+
checksum = "02faf625bb10ba893e3ae620f19c9fb1b5f8fcae0fe4eb86bb3f2230fad75edb"
|
|
372
364
|
dependencies = [
|
|
373
365
|
"rb-sys-build",
|
|
374
366
|
]
|
|
375
367
|
|
|
376
368
|
[[package]]
|
|
377
369
|
name = "rb-sys-build"
|
|
378
|
-
version = "0.9.
|
|
370
|
+
version = "0.9.130"
|
|
379
371
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
380
|
-
checksum = "
|
|
372
|
+
checksum = "05be6f9c86fe5482808162826f6c047d093b3670582296c770de1d94f8066694"
|
|
381
373
|
dependencies = [
|
|
382
374
|
"bindgen",
|
|
383
375
|
"lazy_static",
|
|
@@ -461,9 +453,9 @@ checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
|
|
461
453
|
|
|
462
454
|
[[package]]
|
|
463
455
|
name = "rustc-hash"
|
|
464
|
-
version = "
|
|
456
|
+
version = "2.1.3"
|
|
465
457
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
466
|
-
checksum = "
|
|
458
|
+
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
|
|
467
459
|
|
|
468
460
|
[[package]]
|
|
469
461
|
name = "rustversion"
|
|
@@ -549,9 +541,9 @@ dependencies = [
|
|
|
549
541
|
|
|
550
542
|
[[package]]
|
|
551
543
|
name = "smallvec"
|
|
552
|
-
version = "1.
|
|
544
|
+
version = "1.16.4"
|
|
553
545
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
554
|
-
checksum = "
|
|
546
|
+
checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8"
|
|
555
547
|
|
|
556
548
|
[[package]]
|
|
557
549
|
name = "syn"
|
|
@@ -672,9 +664,9 @@ dependencies = [
|
|
|
672
664
|
|
|
673
665
|
[[package]]
|
|
674
666
|
name = "yrs"
|
|
675
|
-
version = "0.28.
|
|
667
|
+
version = "0.28.1"
|
|
676
668
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
677
|
-
checksum = "
|
|
669
|
+
checksum = "9f7716b4846f9fab489af2ed7ab31c4554f5fe6965ede2392b9cdfed0e5087ff"
|
|
678
670
|
dependencies = [
|
|
679
671
|
"arc-swap",
|
|
680
672
|
"async-lock",
|
data/README.md
CHANGED
|
@@ -76,15 +76,21 @@ doc = post.collaborative_document(:body).y_doc
|
|
|
76
76
|
doc.read_text("content") # or Y::Lexxy.new(doc).to_html for rich text
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
Install the gem and
|
|
79
|
+
Install the gem and run its generator:
|
|
80
80
|
|
|
81
81
|
```
|
|
82
|
-
|
|
83
|
-
npm install yrby-client yjs y-protocols @rails/actioncable
|
|
84
|
-
|
|
82
|
+
bundle add yrby-rails # depends on yrby
|
|
85
83
|
bin/rails generate yrby:install && bin/rails db:migrate
|
|
86
84
|
```
|
|
87
85
|
|
|
86
|
+
In an app that uses import maps, the generator pins `yrby-client`, `yjs`, and
|
|
87
|
+
`@rails/actioncable` to JavaScript the gem ships. With a bundler, install the
|
|
88
|
+
npm packages instead:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
npm install yrby-client yjs y-protocols @rails/actioncable
|
|
92
|
+
```
|
|
93
|
+
|
|
88
94
|
## Contents
|
|
89
95
|
|
|
90
96
|
- [Scope](#scope)
|
|
@@ -101,7 +107,7 @@ bin/rails generate yrby:install && bin/rails db:migrate
|
|
|
101
107
|
- [Rendering to HTML](#rendering-to-html)
|
|
102
108
|
- [Protocol codec (module functions)](#protocol-codec-module-functions)
|
|
103
109
|
- [ActionCable Integration](#actioncable-integration)
|
|
104
|
-
- [Experimental: writing from Ruby](#experimental-writing-from-ruby)
|
|
110
|
+
- [Experimental: writing from Ruby, and collaborators](#experimental-writing-from-ruby-and-collaborators)
|
|
105
111
|
- [Thread Safety](#thread-safety)
|
|
106
112
|
- [Parallelism (GVL release)](#parallelism-gvl-release)
|
|
107
113
|
- [Message Type Constants](#message-type-constants)
|
|
@@ -262,6 +268,7 @@ doc.read_text("prosemirror") # => plain text of a Y.Text root, or nil
|
|
|
262
268
|
doc.read_xml("root") # => text of an XML root, one block per line
|
|
263
269
|
doc.read_map("state") # => a Y.Map root as a JSON string; JSON.parse it
|
|
264
270
|
doc.read_array("cards") # => a Y.Array root as a JSON string; JSON.parse it
|
|
271
|
+
doc.read_text_delta("body") # => a Y.Text root with its formatting, as a JSON string (Yjs's toDelta)
|
|
265
272
|
```
|
|
266
273
|
|
|
267
274
|
### Pending structs and gap-free state
|
|
@@ -359,6 +366,34 @@ types replaces the built-in one.
|
|
|
359
366
|
In both renderers, an unknown node still renders its text and nested blocks as
|
|
360
367
|
readable markup.
|
|
361
368
|
|
|
369
|
+
#### `Y::Trix`
|
|
370
|
+
|
|
371
|
+
```ruby
|
|
372
|
+
Y::Trix.new(doc).to_html # the root named "trix"
|
|
373
|
+
Y::Trix.new(doc).to_html("body") # another root
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Renders a [Trix](https://trix-editor.org) document shared with the
|
|
377
|
+
[y-trix](https://github.com/jpcamara/y-trix) binding to the HTML Trix itself
|
|
378
|
+
saves, which is what Action Text stores. y-trix keeps the whole document in
|
|
379
|
+
one `Y.Text`: the text carries Trix's attributes (bold, italic, strike,
|
|
380
|
+
href), an attachment is an embed, and each block ends in a line break whose
|
|
381
|
+
attributes name the block (heading, quote, code, list item, and how they
|
|
382
|
+
nest). `Y::Trix` reads that with `Doc#read_text_delta` and is plain Ruby.
|
|
383
|
+
|
|
384
|
+
The output is checked against a few hundred documents captured from real
|
|
385
|
+
Trix editors, attachments and nested lists included
|
|
386
|
+
(`test/fixtures/trix.json`).
|
|
387
|
+
|
|
388
|
+
Nothing in the document is trusted. Text is escaped, only the attributes
|
|
389
|
+
Trix knows are read, and links and images keep only URLs a browser would not
|
|
390
|
+
run. A content attachment (a mention, an embed card) stores HTML of its own,
|
|
391
|
+
and that is left out unless you say how to make it safe:
|
|
392
|
+
|
|
393
|
+
```ruby
|
|
394
|
+
Y::Trix.new(doc, content: ->(html) { sanitize(html) }).to_html
|
|
395
|
+
```
|
|
396
|
+
|
|
362
397
|
#### Custom nodes and marks
|
|
363
398
|
|
|
364
399
|
The built-in schemas match what Tiptap and Lexxy ship. When your app adds its
|
|
@@ -664,6 +699,16 @@ the `authorize_document` block with the record and the attribute name, or to
|
|
|
664
699
|
accept any valid grant when there's no block. A subclass can override
|
|
665
700
|
`authorized?` directly and read the located record from `record`.
|
|
666
701
|
|
|
702
|
+
A page subscribes to the channel its document names, `Y::DocumentChannel`
|
|
703
|
+
unless the model says otherwise. Name a subclass where you declare the
|
|
704
|
+
attribute, and the tag, a Ruby client, and a collaborator all use it:
|
|
705
|
+
|
|
706
|
+
```ruby
|
|
707
|
+
class Post < ApplicationRecord
|
|
708
|
+
has_collaborative_document :body, channel: "PostDocumentChannel"
|
|
709
|
+
end
|
|
710
|
+
```
|
|
711
|
+
|
|
667
712
|
### Grant lifetime and refresh
|
|
668
713
|
|
|
669
714
|
A grant lasts as long as GlobalID's signed-id default, which is one month under
|
|
@@ -1077,7 +1122,7 @@ The browser clients manage presence (cursors, selections). The server doesn't
|
|
|
1077
1122
|
set or hold presence state, and it relays awareness frames without reading
|
|
1078
1123
|
them. See `yrby-client` for the client-side awareness API.
|
|
1079
1124
|
|
|
1080
|
-
## Experimental: writing from Ruby
|
|
1125
|
+
## Experimental: writing from Ruby, and collaborators
|
|
1081
1126
|
|
|
1082
1127
|
These APIs are new. They may change in any minor release, and they aren't
|
|
1083
1128
|
covered by yrby's usual compatibility promise.
|
|
@@ -1088,6 +1133,12 @@ covered by yrby's usual compatibility promise.
|
|
|
1088
1133
|
- Anchors: a block's identity as a value
|
|
1089
1134
|
- Streaming into a document with `Doc#edit`
|
|
1090
1135
|
- Editing a record's document from Ruby
|
|
1136
|
+
- From the `yrby-agent` gem: joining a document from a Ruby process with
|
|
1137
|
+
`Y::ActionCable::Client`, collaborators with `Y::Collaborator`, and agents
|
|
1138
|
+
with `Y::Agent`
|
|
1139
|
+
|
|
1140
|
+
`require "y/action_cable/client"`, `require "y/collaborator"`, and
|
|
1141
|
+
`require "y/agent"` print a warning in Ruby's `:experimental` category. `Warning[:experimental] = false` turns it off.
|
|
1091
1142
|
|
|
1092
1143
|
## Thread Safety
|
|
1093
1144
|
|
data/ext/yrby/Cargo.toml
CHANGED
|
@@ -12,7 +12,7 @@ crate-type = ["cdylib"]
|
|
|
12
12
|
[dependencies]
|
|
13
13
|
magnus = "0.8"
|
|
14
14
|
rb-sys = "0.9"
|
|
15
|
-
yrs = { version = "0.28", features = ["sync"] }
|
|
15
|
+
yrs = { version = "0.28.1", features = ["sync"] }
|
|
16
16
|
serde_json = "1.0"
|
|
17
17
|
yjs-html-core = { path = "crates/html-core" }
|
|
18
18
|
lexical-yjs-html = { path = "crates/lexical-html" }
|
data/ext/yrby/src/array.rs
CHANGED
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
|
|
15
15
|
use magnus::{prelude::*, typed_data::Obj, Error, Ruby, Value};
|
|
16
16
|
use yrs::branch::BranchID;
|
|
17
|
-
use yrs::{Any, Array, ArrayRef, Doc, Transact};
|
|
17
|
+
use yrs::{Any, Array, ArrayRef, Doc, TextPrelim, Transact};
|
|
18
18
|
|
|
19
19
|
use crate::map::RbMap;
|
|
20
20
|
use crate::nogvl;
|
|
21
21
|
use crate::read::out_to_any;
|
|
22
22
|
use crate::shared::{
|
|
23
|
-
any_to_ruby, element_index,
|
|
24
|
-
Child,
|
|
23
|
+
any_to_ruby, element_index, identity, insert_index, resolve, ruby_to_invalue, to_in, write,
|
|
24
|
+
Child,
|
|
25
25
|
};
|
|
26
26
|
use crate::text::RbText;
|
|
27
27
|
|
|
@@ -162,29 +162,39 @@ impl RbArray {
|
|
|
162
162
|
let ruby = Ruby::get().unwrap();
|
|
163
163
|
let iv = ruby_to_invalue(&ruby, value)?;
|
|
164
164
|
let (doc, id) = (&self.doc, &self.id);
|
|
165
|
-
|
|
166
|
-
let
|
|
167
|
-
let
|
|
168
|
-
|
|
169
|
-
a.insert(&mut txn, at, to_in(iv));
|
|
165
|
+
write(doc, move |txn| {
|
|
166
|
+
let a = resolve::<ArrayRef, _>(txn, id).ok_or("array no longer exists")?;
|
|
167
|
+
let at = insert_index(index, a.len(txn));
|
|
168
|
+
a.insert(txn, at, to_in(iv));
|
|
170
169
|
Ok(())
|
|
171
170
|
})
|
|
172
171
|
}
|
|
173
172
|
|
|
173
|
+
/// Insert a new `Y.Text` holding `content` at `index` (the same index
|
|
174
|
+
/// rules as `insert`) and return a live handle to it.
|
|
175
|
+
fn insert_text(&self, index: i64, content: String) -> Result<RbText, Error> {
|
|
176
|
+
let (doc, id) = (&self.doc, &self.id);
|
|
177
|
+
let text = write(doc, move |txn| {
|
|
178
|
+
let a = resolve::<ArrayRef, _>(txn, id).ok_or("array no longer exists")?;
|
|
179
|
+
let at = insert_index(index, a.len(txn));
|
|
180
|
+
Ok(identity(&a.insert(txn, at, TextPrelim::new(content))))
|
|
181
|
+
})?;
|
|
182
|
+
Ok(RbText::new(self.doc.clone(), text))
|
|
183
|
+
}
|
|
184
|
+
|
|
174
185
|
/// Remove the element at `index`, returning its previous snapshot value.
|
|
175
186
|
fn delete_at(&self, index: i64) -> Result<Value, Error> {
|
|
176
187
|
let (doc, id) = (&self.doc, &self.id);
|
|
177
|
-
let prev: Option<Any> =
|
|
178
|
-
let
|
|
179
|
-
let Some(a) = resolve::<ArrayRef, _>(&txn, id) else {
|
|
188
|
+
let prev: Option<Any> = write(doc, move |txn| {
|
|
189
|
+
let Some(a) = resolve::<ArrayRef, _>(txn, id) else {
|
|
180
190
|
return Ok(None);
|
|
181
191
|
};
|
|
182
|
-
let Some(i) = element_index(index, a.len(
|
|
192
|
+
let Some(i) = element_index(index, a.len(txn)) else {
|
|
183
193
|
return Ok(None);
|
|
184
194
|
};
|
|
185
195
|
// Convert before removing: a removed shared ref would dangle.
|
|
186
|
-
let prev = a.get(
|
|
187
|
-
a.remove(
|
|
196
|
+
let prev = a.get(txn, i).map(|v| out_to_any(txn, &v));
|
|
197
|
+
a.remove(txn, i);
|
|
188
198
|
Ok(prev)
|
|
189
199
|
})?;
|
|
190
200
|
let ruby = Ruby::get().unwrap();
|
|
@@ -196,12 +206,11 @@ impl RbArray {
|
|
|
196
206
|
|
|
197
207
|
fn clear(&self) -> Result<(), Error> {
|
|
198
208
|
let (doc, id) = (&self.doc, &self.id);
|
|
199
|
-
|
|
200
|
-
let
|
|
201
|
-
|
|
202
|
-
let len = a.len(&txn);
|
|
209
|
+
write(doc, move |txn| {
|
|
210
|
+
if let Some(a) = resolve::<ArrayRef, _>(txn, id) {
|
|
211
|
+
let len = a.len(txn);
|
|
203
212
|
if len > 0 {
|
|
204
|
-
a.remove_range(
|
|
213
|
+
a.remove_range(txn, 0, len);
|
|
205
214
|
}
|
|
206
215
|
}
|
|
207
216
|
Ok(())
|
|
@@ -215,12 +224,11 @@ impl RbArray {
|
|
|
215
224
|
let ruby = Ruby::get().unwrap();
|
|
216
225
|
let iv = ruby_to_invalue(&ruby, value)?;
|
|
217
226
|
let (doc, id) = (&self.doc, &self.id);
|
|
218
|
-
|
|
219
|
-
let
|
|
220
|
-
let
|
|
221
|
-
|
|
222
|
-
a.
|
|
223
|
-
a.insert(&mut txn, i, to_in(iv));
|
|
227
|
+
write(doc, move |txn| {
|
|
228
|
+
let a = resolve::<ArrayRef, _>(txn, id).ok_or("array no longer exists")?;
|
|
229
|
+
let i = element_index(index, a.len(txn)).ok_or("index out of range")?;
|
|
230
|
+
a.remove(txn, i);
|
|
231
|
+
a.insert(txn, i, to_in(iv));
|
|
224
232
|
Ok(())
|
|
225
233
|
})?;
|
|
226
234
|
Ok(value)
|
|
@@ -246,6 +254,10 @@ pub fn define(ruby: &Ruby, module: magnus::RModule) -> Result<(), Error> {
|
|
|
246
254
|
class.define_method("push", magnus::method!(RbArray::push, 1))?;
|
|
247
255
|
class.define_method("<<", magnus::method!(RbArray::push, 1))?;
|
|
248
256
|
class.define_method("insert", magnus::method!(RbArray::insert, 2))?;
|
|
257
|
+
class.define_method(
|
|
258
|
+
"native_insert_text",
|
|
259
|
+
magnus::method!(RbArray::insert_text, 2),
|
|
260
|
+
)?;
|
|
249
261
|
class.define_method("delete_at", magnus::method!(RbArray::delete_at, 1))?;
|
|
250
262
|
class.define_method("clear", magnus::method!(RbArray::clear, 0))?;
|
|
251
263
|
class.define_method("size", magnus::method!(RbArray::size, 0))?;
|