y-rb 0.3.2-x64-mingw32 → 0.4.0-x64-mingw32
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/ext/yrb/Cargo.toml +5 -6
- data/ext/yrb/src/awareness.rs +5 -5
- data/ext/yrb/src/lib.rs +81 -35
- data/ext/yrb/src/yarray.rs +68 -33
- data/ext/yrb/src/ydoc.rs +53 -10
- data/ext/yrb/src/ymap.rs +47 -24
- data/ext/yrb/src/ytext.rs +55 -60
- data/ext/yrb/src/ytransaction.rs +71 -23
- data/ext/yrb/src/yvalue.rs +26 -7
- data/ext/yrb/src/yxml_element.rs +133 -72
- data/ext/yrb/src/yxml_fragment.rs +16 -0
- data/ext/yrb/src/yxml_text.rs +96 -56
- data/lib/2.7/yrb.so +0 -0
- data/lib/3.0/yrb.so +0 -0
- data/lib/y/array.rb +114 -100
- data/lib/y/awareness.rb +40 -14
- data/lib/y/doc.rb +77 -71
- data/lib/y/map.rb +39 -42
- data/lib/y/text.rb +92 -96
- data/lib/y/transaction.rb +31 -13
- data/lib/y/version.rb +1 -1
- data/lib/y/xml.rb +259 -227
- data/lib/y-rb.rb +1 -1
- metadata +5 -4
data/lib/y/text.rb
CHANGED
@@ -25,7 +25,7 @@ module Y
|
|
25
25
|
|
26
26
|
# Create a new text instance
|
27
27
|
#
|
28
|
-
# @param [Y::Doc]
|
28
|
+
# @param doc [Y::Doc]
|
29
29
|
def initialize(doc = nil)
|
30
30
|
@document = doc || Y::Doc.new
|
31
31
|
|
@@ -34,9 +34,10 @@ module Y
|
|
34
34
|
|
35
35
|
# Appends a string at the end of the text
|
36
36
|
#
|
37
|
+
# @param str [String]
|
37
38
|
# @return [void]
|
38
39
|
def <<(str)
|
39
|
-
ytext_push(
|
40
|
+
document.current_transaction { |tx| ytext_push(tx, str) }
|
40
41
|
end
|
41
42
|
|
42
43
|
# Attach listener to text changes
|
@@ -62,8 +63,8 @@ module Y
|
|
62
63
|
# # todo: required, otherwise segfault
|
63
64
|
# local.commit
|
64
65
|
#
|
65
|
-
# @param [Proc]
|
66
|
-
# @param [Block]
|
66
|
+
# @param callback [Proc]
|
67
|
+
# @param block [Block]
|
67
68
|
# @return [Integer]
|
68
69
|
def attach(callback, &block)
|
69
70
|
return ytext_observe(callback) unless callback.nil?
|
@@ -73,7 +74,7 @@ module Y
|
|
73
74
|
|
74
75
|
# Detach listener
|
75
76
|
#
|
76
|
-
# @param [Integer]
|
77
|
+
# @param subscription_id [Integer]
|
77
78
|
# @return [void]
|
78
79
|
def detach(subscription_id)
|
79
80
|
ytext_unobserve(subscription_id)
|
@@ -92,7 +93,7 @@ module Y
|
|
92
93
|
length.zero?
|
93
94
|
end
|
94
95
|
|
95
|
-
# rubocop:disable Metrics/
|
96
|
+
# rubocop:disable Metrics/MethodLength
|
96
97
|
|
97
98
|
# Insert a value at position and with optional attributes. This method is
|
98
99
|
# similar to [String#insert](https://ruby-doc.org/core-3.1.2/String.html),
|
@@ -114,32 +115,34 @@ module Y
|
|
114
115
|
# - Array (where element types must be supported)
|
115
116
|
# - Hash (where the the types of key and values must be supported)
|
116
117
|
#
|
117
|
-
# @param [Integer]
|
118
|
-
# @param [String
|
119
|
-
# @param [Hash|nil]
|
118
|
+
# @param index [Integer]
|
119
|
+
# @param value [String|Numeric|Array|Hash]
|
120
|
+
# @param attrs [Hash|nil]
|
120
121
|
# @return [void]
|
121
122
|
def insert(index, value, attrs = nil)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
document.current_transaction do |tx|
|
124
|
+
if value.is_a?(String)
|
125
|
+
ytext_insert(tx, index, value) if attrs.nil?
|
126
|
+
unless attrs.nil?
|
127
|
+
ytext_insert_with_attributes(tx, index, value, attrs)
|
128
|
+
end
|
129
|
+
return nil
|
126
130
|
end
|
127
|
-
return nil
|
128
|
-
end
|
129
131
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
132
|
+
if can_insert?(value)
|
133
|
+
ytext_insert_embed(tx, index, value) if attrs.nil?
|
134
|
+
unless attrs.nil?
|
135
|
+
ytext_insert_embed_with_attributes(tx, index, value, attrs)
|
136
|
+
end
|
137
|
+
return nil
|
134
138
|
end
|
135
|
-
return nil
|
136
|
-
end
|
137
139
|
|
138
|
-
|
139
|
-
|
140
|
+
raise ArgumentError,
|
141
|
+
"Can't insert value. `#{value.class.name}` isn't supported."
|
142
|
+
end
|
140
143
|
end
|
141
144
|
|
142
|
-
# rubocop:enable Metrics/
|
145
|
+
# rubocop:enable Metrics/MethodLength
|
143
146
|
|
144
147
|
# Applies formatting to text
|
145
148
|
#
|
@@ -150,19 +153,21 @@ module Y
|
|
150
153
|
# attrs = {format: "bold"}
|
151
154
|
# text.format(0, 2, attrs)
|
152
155
|
#
|
153
|
-
# @param [Integer]
|
154
|
-
# @param [Integer]
|
155
|
-
# @param [Hash]
|
156
|
+
# @param index [Integer]
|
157
|
+
# @param length [Integer]
|
158
|
+
# @param attrs [Hash]
|
156
159
|
# @return [void]
|
157
160
|
def format(index, length, attrs)
|
158
|
-
|
161
|
+
document.current_transaction do |tx|
|
162
|
+
ytext_format(tx, index, length, attrs)
|
163
|
+
end
|
159
164
|
end
|
160
165
|
|
161
166
|
# Returns length of text
|
162
167
|
#
|
163
168
|
# @return [Integer] Length of text
|
164
169
|
def length
|
165
|
-
ytext_length
|
170
|
+
document.current_transaction { |tx| ytext_length(tx) }
|
166
171
|
end
|
167
172
|
|
168
173
|
alias size length
|
@@ -219,35 +224,37 @@ module Y
|
|
219
224
|
#
|
220
225
|
# @return [void]
|
221
226
|
def slice!(*args)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
227
|
+
document.current_transaction do |tx|
|
228
|
+
if args.size.zero?
|
229
|
+
raise ArgumentError,
|
230
|
+
"Provide one of `index`, `range`, `start, length` as arguments"
|
231
|
+
end
|
226
232
|
|
227
|
-
|
228
|
-
|
233
|
+
if args.size == 1
|
234
|
+
arg = args.first
|
229
235
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
236
|
+
if arg.is_a?(Range)
|
237
|
+
ytext_remove_range(tx, arg.first, arg.last - arg.first)
|
238
|
+
return nil
|
239
|
+
end
|
234
240
|
|
235
|
-
|
236
|
-
|
237
|
-
|
241
|
+
if arg.is_a?(Numeric)
|
242
|
+
ytext_remove_range(tx, arg.to_int, 1)
|
243
|
+
return nil
|
244
|
+
end
|
238
245
|
end
|
239
|
-
end
|
240
246
|
|
241
|
-
|
242
|
-
|
247
|
+
if args.size == 2
|
248
|
+
start, length = args
|
243
249
|
|
244
|
-
|
245
|
-
|
246
|
-
|
250
|
+
if start.is_a?(Numeric) && length.is_a?(Numeric)
|
251
|
+
ytext_remove_range(tx, start, length)
|
252
|
+
return nil
|
253
|
+
end
|
247
254
|
end
|
248
|
-
end
|
249
255
|
|
250
|
-
|
256
|
+
raise ArgumentError, "Please check your arguments, can't slice."
|
257
|
+
end
|
251
258
|
end
|
252
259
|
|
253
260
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
@@ -263,7 +270,7 @@ module Y
|
|
263
270
|
#
|
264
271
|
# @return [String]
|
265
272
|
def to_s
|
266
|
-
ytext_to_s
|
273
|
+
document.current_transaction { |tx| ytext_to_s(tx) }
|
267
274
|
end
|
268
275
|
|
269
276
|
private
|
@@ -277,75 +284,74 @@ module Y
|
|
277
284
|
value.is_a?(Hash)
|
278
285
|
end
|
279
286
|
|
280
|
-
#
|
281
|
-
|
282
|
-
# @!method ytext_insert(transaction, index, chunk)
|
287
|
+
# @!method ytext_insert(tx, index, chunk)
|
283
288
|
# Insert into text at position
|
284
289
|
#
|
285
|
-
# @param [Y::Transaction]
|
286
|
-
# @param [Integer]
|
287
|
-
# @param [String]
|
290
|
+
# @param transaction [Y::Transaction]
|
291
|
+
# @param index [Integer]
|
292
|
+
# @param chunk [String]
|
288
293
|
# @return [nil]
|
289
294
|
|
290
|
-
# @!method ytext_insert_embed(
|
295
|
+
# @!method ytext_insert_embed(tx, index, content)
|
291
296
|
# Insert into text at position
|
292
297
|
#
|
293
|
-
# @param [Y::Transaction]
|
294
|
-
# @param [Integer]
|
295
|
-
# @param [Y::Text
|
298
|
+
# @param tx [Y::Transaction]
|
299
|
+
# @param index [Integer]
|
300
|
+
# @param content [Y::Text|Y::Array|Y::Map]
|
296
301
|
# @return [nil]
|
297
302
|
|
298
|
-
# @!method ytext_insert_embed_with_attributes(
|
303
|
+
# @!method ytext_insert_embed_with_attributes(tx, index, embed, attrs)
|
299
304
|
# Insert into text at position
|
300
305
|
#
|
301
|
-
# @param [Y::Transaction]
|
302
|
-
# @param [Integer]
|
303
|
-
# @param [Y::Text, Y::Array, Y::Map]
|
304
|
-
# @param [Hash]
|
306
|
+
# @param tx [Y::Transaction]
|
307
|
+
# @param index [Integer]
|
308
|
+
# @param embed [Y::Text, Y::Array, Y::Map]
|
309
|
+
# @param attrs [Hash]
|
305
310
|
# @return [nil]
|
306
311
|
|
307
|
-
# @!method ytext_insert_with_attributes(
|
312
|
+
# @!method ytext_insert_with_attributes(tx, index, chunk, attrs)
|
308
313
|
# Insert into text at position
|
309
314
|
#
|
310
|
-
# @param [Y::Transaction]
|
311
|
-
# @param [Integer]
|
312
|
-
# @param [String]
|
313
|
-
# @param [Hash]
|
315
|
+
# @param tx [Y::Transaction]
|
316
|
+
# @param index [Integer]
|
317
|
+
# @param chunk [String]
|
318
|
+
# @param attrs [Hash]
|
314
319
|
# @return [nil]
|
315
320
|
|
316
|
-
# @!method ytext_push(
|
321
|
+
# @!method ytext_push(tx, value)
|
317
322
|
# Returns length of text
|
318
323
|
#
|
319
|
-
# @param [Y::Transaction]
|
320
|
-
# @param [String]
|
324
|
+
# @param tx [Y::Transaction]
|
325
|
+
# @param value [String]
|
321
326
|
# @return [nil]
|
322
327
|
|
323
|
-
# @!method ytext_remove_range(
|
328
|
+
# @!method ytext_remove_range(tx, index, length)
|
324
329
|
# Removes a range from text
|
325
330
|
#
|
326
|
-
# @param [Y::Transaction]
|
327
|
-
# @param [Integer]
|
328
|
-
# @param [Integer]
|
331
|
+
# @param tx [Y::Transaction]
|
332
|
+
# @param index [Integer]
|
333
|
+
# @param length [Integer]
|
329
334
|
# @return [nil]
|
330
335
|
|
331
|
-
# @!method ytext_format(
|
336
|
+
# @!method ytext_format(tx, index, length, attrs)
|
332
337
|
# Formats a text range
|
333
338
|
#
|
334
|
-
# @param [Y::Transaction]
|
335
|
-
# @param [Integer]
|
336
|
-
# @param [Integer]
|
337
|
-
# @param [Hash]
|
339
|
+
# @param tx [Y::Transaction]
|
340
|
+
# @param index [Integer]
|
341
|
+
# @param length [Integer]
|
342
|
+
# @param attrs [Hash]
|
338
343
|
# @return [nil]
|
339
344
|
|
340
|
-
# @!method ytext_length()
|
345
|
+
# @!method ytext_length(tx)
|
341
346
|
# Returns length of text
|
342
347
|
#
|
348
|
+
# @param tx [Y::Transaction]
|
343
349
|
# @return [Integer]
|
344
350
|
|
345
351
|
# @!method ytext_observe(proc)
|
346
352
|
# Observe text changes
|
347
353
|
#
|
348
|
-
# @param [Proc]
|
354
|
+
# @param proc [Proc]
|
349
355
|
# @return [Integer]
|
350
356
|
|
351
357
|
# @!method ytext_to_s()
|
@@ -356,17 +362,7 @@ module Y
|
|
356
362
|
# @!method ytext_unobserve(subscription_id)
|
357
363
|
# Detach listener
|
358
364
|
#
|
359
|
-
# @param [Integer]
|
365
|
+
# @param subscription_id [Integer]
|
360
366
|
# @return [void]
|
361
|
-
|
362
|
-
# rubocop:enable Layout/LineLength
|
363
|
-
|
364
|
-
# A reference to the current active transaction of the document this map
|
365
|
-
# belongs to.
|
366
|
-
#
|
367
|
-
# @return [Y::Transaction] A transaction object
|
368
|
-
def transaction
|
369
|
-
document.current_transaction
|
370
|
-
end
|
371
367
|
end
|
372
368
|
end
|
data/lib/y/transaction.rb
CHANGED
@@ -13,10 +13,10 @@ module Y
|
|
13
13
|
super()
|
14
14
|
end
|
15
15
|
|
16
|
-
# Applies the
|
16
|
+
# Applies the encoded update on this document. This will bring the
|
17
17
|
# the document to the same state as the one the update is from.
|
18
18
|
#
|
19
|
-
# @param [::Array<Integer>]
|
19
|
+
# @param update [::Array<Integer>]
|
20
20
|
# @return [void]
|
21
21
|
def apply(update)
|
22
22
|
ytransaction_apply_update(update)
|
@@ -31,7 +31,7 @@ module Y
|
|
31
31
|
|
32
32
|
# Create or get array type
|
33
33
|
#
|
34
|
-
# @param [String]
|
34
|
+
# @param name [String]
|
35
35
|
# @return [Y::Array]
|
36
36
|
def get_array(name)
|
37
37
|
array = ytransaction_get_array(name)
|
@@ -41,7 +41,7 @@ module Y
|
|
41
41
|
|
42
42
|
# Create or get map type
|
43
43
|
#
|
44
|
-
# @param [String]
|
44
|
+
# @param name [String]
|
45
45
|
# @return [Y::Map]
|
46
46
|
def get_map(name)
|
47
47
|
map = ytransaction_get_map(name)
|
@@ -51,7 +51,7 @@ module Y
|
|
51
51
|
|
52
52
|
# Create or get text type
|
53
53
|
#
|
54
|
-
# @param [String]
|
54
|
+
# @param name [String]
|
55
55
|
# @return [Y::Text]
|
56
56
|
def get_text(name)
|
57
57
|
text = ytransaction_get_text(name)
|
@@ -61,7 +61,7 @@ module Y
|
|
61
61
|
|
62
62
|
# Create or get XMLElement type
|
63
63
|
#
|
64
|
-
# @param [String]
|
64
|
+
# @param name [String]
|
65
65
|
# @return [Y::XMLElement]
|
66
66
|
def get_xml_element(name)
|
67
67
|
xml_element = ytransaction_get_xml_element(name)
|
@@ -69,9 +69,19 @@ module Y
|
|
69
69
|
xml_element
|
70
70
|
end
|
71
71
|
|
72
|
+
# Create or get XMLFragment type
|
73
|
+
#
|
74
|
+
# @param name [String]
|
75
|
+
# @return [Y::XMLFragment]
|
76
|
+
def get_xml_fragment(name)
|
77
|
+
xml_fragment = ytransaction_get_xml_fragment(name)
|
78
|
+
xml_fragment.document = document
|
79
|
+
xml_fragment
|
80
|
+
end
|
81
|
+
|
72
82
|
# Create or get XMLText type
|
73
83
|
#
|
74
|
-
# @param [String]
|
84
|
+
# @param name [String]
|
75
85
|
# @return [Y::XMLText]
|
76
86
|
def get_xml_text(name)
|
77
87
|
xml_text = ytransaction_get_xml_text(name)
|
@@ -89,7 +99,7 @@ module Y
|
|
89
99
|
# @!method ytransaction_apply_update(update)
|
90
100
|
# Returns or creates an array by name
|
91
101
|
#
|
92
|
-
# @param [::Array<Integer>]
|
102
|
+
# @param update [::Array<Integer>]
|
93
103
|
# @return [void]
|
94
104
|
# @!visibility private
|
95
105
|
|
@@ -101,36 +111,44 @@ module Y
|
|
101
111
|
# @!method ytransaction_get_array(name)
|
102
112
|
# Returns or creates an array by name
|
103
113
|
#
|
104
|
-
# @param [String]
|
114
|
+
# @param name [String] Name of the array structure to retrieve or create
|
105
115
|
# @return [Y::Array] Array structure
|
106
116
|
# @!visibility private
|
107
117
|
|
108
118
|
# @!method ytransaction_get_map(name)
|
109
119
|
# Returns or creates a map structure by name
|
110
120
|
#
|
111
|
-
# @param [String]
|
121
|
+
# @param name [String] Name of the map structure to retrieve or create
|
112
122
|
# @return [Y::Map] Map structure
|
113
123
|
# @!visibility private
|
114
124
|
|
115
125
|
# @!method ytransaction_get_text(name)
|
116
126
|
# Returns or creates a text structure by name
|
117
127
|
#
|
118
|
-
# @param [String]
|
128
|
+
# @param name [String] Name of the text structure to retrieve or create
|
119
129
|
# @return [Y::Text] Text structure
|
120
130
|
# @!visibility private
|
121
131
|
|
122
132
|
# @!method ytransaction_get_xml_element(name)
|
123
133
|
# Returns or creates a XML structure by name
|
124
134
|
#
|
125
|
-
# @param [String]
|
135
|
+
# @param name [String] Name of the XML element structure to retrieve or
|
126
136
|
# create
|
127
137
|
# @return [Y::XMLElement] XMLElement structure
|
128
138
|
# @!visibility private
|
129
139
|
|
140
|
+
# @!method ytransaction_get_xml_fragment(name)
|
141
|
+
# Returns or creates a XML fragment
|
142
|
+
#
|
143
|
+
# @param name [String] Name of the XML fragment to retrieve or
|
144
|
+
# create by
|
145
|
+
# @return [Y::XMLFragment] XMLFragment structure
|
146
|
+
# @!visibility private
|
147
|
+
|
130
148
|
# @!method ytransaction_get_xml_text(name)
|
131
149
|
# Returns or creates a XML structure by name
|
132
150
|
#
|
133
|
-
# @param [String]
|
151
|
+
# @param name [String] Name of the XML element structure to retrieve or
|
134
152
|
# create
|
135
153
|
# @return [Y::XMLElement] XMLElement structure
|
136
154
|
# @!visibility private
|
data/lib/y/version.rb
CHANGED