rbs 3.0.0.dev.2 → 3.0.0.dev.3
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/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -0
- data/Gemfile.lock +11 -11
- data/Rakefile +2 -2
- data/Steepfile +1 -1
- data/core/array.rbs +573 -423
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +8 -0
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +113 -175
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +110 -17
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/parser.c +5 -6
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +9 -2
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/environment.rb +6 -5
- data/lib/rbs/environment_loader.rb +3 -2
- data/lib/rbs/errors.rb +18 -0
- data/lib/rbs/locator.rb +26 -7
- data/lib/rbs/sorter.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/sig/collection/sources.rbs +32 -3
- data/sig/environment.rbs +2 -3
- data/sig/locator.rbs +14 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +8 -6
- data/core/deprecated.rbs +0 -9
- data/sig/shims/ripper.rbs +0 -8
data/stdlib/pstore/0/pstore.rbs
CHANGED
|
@@ -1,122 +1,349 @@
|
|
|
1
1
|
# <!-- rdoc-file=lib/pstore.rb -->
|
|
2
|
-
# PStore implements a file based persistence mechanism based on a Hash.
|
|
3
|
-
# code can store hierarchies of Ruby objects (values) into the data store
|
|
4
|
-
#
|
|
5
|
-
#
|
|
2
|
+
# PStore implements a file based persistence mechanism based on a Hash. User
|
|
3
|
+
# code can store hierarchies of Ruby objects (values) into the data store by
|
|
4
|
+
# name (keys). An object hierarchy may be just a single object. User code may
|
|
5
|
+
# later read values back from the data store or even update data, as needed.
|
|
6
6
|
#
|
|
7
7
|
# The transactional behavior ensures that any changes succeed or fail together.
|
|
8
8
|
# This can be used to ensure that the data store is not left in a transitory
|
|
9
9
|
# state, where some values were updated but others were not.
|
|
10
10
|
#
|
|
11
11
|
# Behind the scenes, Ruby objects are stored to the data store file with
|
|
12
|
-
# Marshal.
|
|
12
|
+
# Marshal. That carries the usual limitations. Proc objects cannot be
|
|
13
13
|
# marshalled, for example.
|
|
14
14
|
#
|
|
15
|
-
#
|
|
15
|
+
# There are three important concepts here (details at the links):
|
|
16
|
+
#
|
|
17
|
+
# * [Store](rdoc-ref:PStore@The+Store): a store is an instance of PStore.
|
|
18
|
+
# * [Entries](rdoc-ref:PStore@Entries): the store is hash-like; each entry is
|
|
19
|
+
# the key for a stored object.
|
|
20
|
+
# * [Transactions](rdoc-ref:PStore@Transactions): each transaction is a
|
|
21
|
+
# collection of prospective changes to the store; a transaction is defined
|
|
22
|
+
# in the block given with a call to PStore#transaction.
|
|
23
|
+
#
|
|
24
|
+
#
|
|
25
|
+
# ## About the Examples
|
|
26
|
+
#
|
|
27
|
+
# Examples on this page need a store that has known properties. They can get a
|
|
28
|
+
# new (and populated) store by calling thus:
|
|
29
|
+
#
|
|
30
|
+
# example_store do |store|
|
|
31
|
+
# # Example code using store goes here.
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# All we really need to know about `example_store` is that it yields a fresh
|
|
35
|
+
# store with a known population of entries; its implementation:
|
|
36
|
+
#
|
|
37
|
+
# require 'pstore'
|
|
38
|
+
# require 'tempfile'
|
|
39
|
+
# # Yield a pristine store for use in examples.
|
|
40
|
+
# def example_store
|
|
41
|
+
# # Create the store in a temporary file.
|
|
42
|
+
# Tempfile.create do |file|
|
|
43
|
+
# store = PStore.new(file)
|
|
44
|
+
# # Populate the store.
|
|
45
|
+
# store.transaction do
|
|
46
|
+
# store[:foo] = 0
|
|
47
|
+
# store[:bar] = 1
|
|
48
|
+
# store[:baz] = 2
|
|
49
|
+
# end
|
|
50
|
+
# yield store
|
|
51
|
+
# end
|
|
52
|
+
# end
|
|
53
|
+
#
|
|
54
|
+
# ## The Store
|
|
55
|
+
#
|
|
56
|
+
# The contents of the store are maintained in a file whose path is specified
|
|
57
|
+
# when the store is created (see PStore.new). The objects are stored and
|
|
58
|
+
# retrieved using module Marshal, which means that certain objects cannot be
|
|
59
|
+
# added to the store; see [Marshal::dump](rdoc-ref:Marshal.dump).
|
|
60
|
+
#
|
|
61
|
+
# ## Entries
|
|
62
|
+
#
|
|
63
|
+
# A store may have any number of entries. Each entry has a key and a value, just
|
|
64
|
+
# as in a hash:
|
|
65
|
+
#
|
|
66
|
+
# * Key: as in a hash, the key can be (almost) any object; see [Hash
|
|
67
|
+
# Keys](rdoc-ref:Hash@Hash+Keys). You may find it convenient to keep it
|
|
68
|
+
# simple by using only symbols or strings as keys.
|
|
69
|
+
# * Value: the value may be any object that can be marshalled by Marshal (see
|
|
70
|
+
# [Marshal::dump](rdoc-ref:Marshal.dump)) and in fact may be a collection
|
|
71
|
+
# (e.g., an array, a hash, a set, a range, etc). That collection may in turn
|
|
72
|
+
# contain nested objects, including collections, to any depth; those objects
|
|
73
|
+
# must also be Marshal-able. See [Hierarchical
|
|
74
|
+
# Values](rdoc-ref:PStore@Hierarchical+Values).
|
|
75
|
+
#
|
|
76
|
+
#
|
|
77
|
+
# ## Transactions
|
|
78
|
+
#
|
|
79
|
+
# ### The Transaction Block
|
|
80
|
+
#
|
|
81
|
+
# The block given with a call to method #transaction# contains a *transaction*,
|
|
82
|
+
# which consists of calls to PStore methods that read from or write to the store
|
|
83
|
+
# (that is, all PStore methods except #transaction itself, #path, and
|
|
84
|
+
# Pstore.new):
|
|
85
|
+
#
|
|
86
|
+
# example_store do |store|
|
|
87
|
+
# store.transaction do
|
|
88
|
+
# store.keys # => [:foo, :bar, :baz]
|
|
89
|
+
# store[:bat] = 3
|
|
90
|
+
# store.keys # => [:foo, :bar, :baz, :bat]
|
|
91
|
+
# end
|
|
92
|
+
# end
|
|
93
|
+
#
|
|
94
|
+
# Execution of the transaction is deferred until the block exits, and is
|
|
95
|
+
# executed *atomically* (all-or-nothing): either all transaction calls are
|
|
96
|
+
# executed, or none are. This maintains the integrity of the store.
|
|
97
|
+
#
|
|
98
|
+
# Other code in the block (including even calls to #path and PStore.new) is
|
|
99
|
+
# executed immediately, not deferred.
|
|
100
|
+
#
|
|
101
|
+
# The transaction block:
|
|
102
|
+
#
|
|
103
|
+
# * May not contain a nested call to #transaction.
|
|
104
|
+
# * Is the only context where methods that read from or write to the store are
|
|
105
|
+
# allowed.
|
|
106
|
+
#
|
|
107
|
+
#
|
|
108
|
+
# As seen above, changes in a transaction are made automatically when the block
|
|
109
|
+
# exits. The block may be exited early by calling method #commit or #abort.
|
|
110
|
+
#
|
|
111
|
+
# * Method #commit triggers the update to the store and exits the block:
|
|
112
|
+
#
|
|
113
|
+
# example_store do |store|
|
|
114
|
+
# store.transaction do
|
|
115
|
+
# store.keys # => [:foo, :bar, :baz]
|
|
116
|
+
# store[:bat] = 3
|
|
117
|
+
# store.commit
|
|
118
|
+
# fail 'Cannot get here'
|
|
119
|
+
# end
|
|
120
|
+
# store.transaction do
|
|
121
|
+
# # Update was completed.
|
|
122
|
+
# store.keys # => [:foo, :bar, :baz, :bat]
|
|
123
|
+
# end
|
|
124
|
+
# end
|
|
125
|
+
#
|
|
126
|
+
# * Method #abort discards the update to the store and exits the block:
|
|
127
|
+
#
|
|
128
|
+
# example_store do |store|
|
|
129
|
+
# store.transaction do
|
|
130
|
+
# store.keys # => [:foo, :bar, :baz]
|
|
131
|
+
# store[:bat] = 3
|
|
132
|
+
# store.abort
|
|
133
|
+
# fail 'Cannot get here'
|
|
134
|
+
# end
|
|
135
|
+
# store.transaction do
|
|
136
|
+
# # Update was not completed.
|
|
137
|
+
# store.keys # => [:foo, :bar, :baz]
|
|
138
|
+
# end
|
|
139
|
+
# end
|
|
140
|
+
#
|
|
141
|
+
#
|
|
142
|
+
# ### Read-Only Transactions
|
|
143
|
+
#
|
|
144
|
+
# By default, a transaction allows both reading from and writing to the store:
|
|
145
|
+
#
|
|
146
|
+
# store.transaction do
|
|
147
|
+
# # Read-write transaction.
|
|
148
|
+
# # Any code except a call to #transaction is allowed here.
|
|
149
|
+
# end
|
|
150
|
+
#
|
|
151
|
+
# If argument `read_only` is passed as `true`, only reading is allowed:
|
|
152
|
+
#
|
|
153
|
+
# store.transaction(true) do
|
|
154
|
+
# # Read-only transaction:
|
|
155
|
+
# # Calls to #transaction, #[]=, and #delete are not allowed here.
|
|
156
|
+
# end
|
|
157
|
+
#
|
|
158
|
+
# ## Hierarchical Values
|
|
159
|
+
#
|
|
160
|
+
# The value for an entry may be a simple object (as seen above). It may also be
|
|
161
|
+
# a hierarchy of objects nested to any depth:
|
|
162
|
+
#
|
|
163
|
+
# deep_store = PStore.new('deep.store')
|
|
164
|
+
# deep_store.transaction do
|
|
165
|
+
# array_of_hashes = [{}, {}, {}]
|
|
166
|
+
# deep_store[:array_of_hashes] = array_of_hashes
|
|
167
|
+
# deep_store[:array_of_hashes] # => [{}, {}, {}]
|
|
168
|
+
# hash_of_arrays = {foo: [], bar: [], baz: []}
|
|
169
|
+
# deep_store[:hash_of_arrays] = hash_of_arrays
|
|
170
|
+
# deep_store[:hash_of_arrays] # => {:foo=>[], :bar=>[], :baz=>[]}
|
|
171
|
+
# deep_store[:hash_of_arrays][:foo].push(:bat)
|
|
172
|
+
# deep_store[:hash_of_arrays] # => {:foo=>[:bat], :bar=>[], :baz=>[]}
|
|
173
|
+
# end
|
|
174
|
+
#
|
|
175
|
+
# And recall that you can use [dig methods](rdoc-ref:dig_methods.rdoc) in a
|
|
176
|
+
# returned hierarchy of objects.
|
|
177
|
+
#
|
|
178
|
+
# ## Working with the Store
|
|
179
|
+
#
|
|
180
|
+
# ### Creating a Store
|
|
181
|
+
#
|
|
182
|
+
# Use method PStore.new to create a store. The new store creates or opens its
|
|
183
|
+
# containing file:
|
|
184
|
+
#
|
|
185
|
+
# store = PStore.new('t.store')
|
|
186
|
+
#
|
|
187
|
+
# ### Modifying the Store
|
|
188
|
+
#
|
|
189
|
+
# Use method #[]= to update or create an entry:
|
|
190
|
+
#
|
|
191
|
+
# example_store do |store|
|
|
192
|
+
# store.transaction do
|
|
193
|
+
# store[:foo] = 1 # Update.
|
|
194
|
+
# store[:bam] = 1 # Create.
|
|
195
|
+
# end
|
|
196
|
+
# end
|
|
197
|
+
#
|
|
198
|
+
# Use method #delete to remove an entry:
|
|
199
|
+
#
|
|
200
|
+
# example_store do |store|
|
|
201
|
+
# store.transaction do
|
|
202
|
+
# store.delete(:foo)
|
|
203
|
+
# store[:foo] # => nil
|
|
204
|
+
# end
|
|
205
|
+
# end
|
|
206
|
+
#
|
|
207
|
+
# ### Retrieving Values
|
|
208
|
+
#
|
|
209
|
+
# Use method #fetch (allows default) or #[] (defaults to `nil`) to retrieve an
|
|
210
|
+
# entry:
|
|
211
|
+
#
|
|
212
|
+
# example_store do |store|
|
|
213
|
+
# store.transaction do
|
|
214
|
+
# store[:foo] # => 0
|
|
215
|
+
# store[:nope] # => nil
|
|
216
|
+
# store.fetch(:baz) # => 2
|
|
217
|
+
# store.fetch(:nope, nil) # => nil
|
|
218
|
+
# store.fetch(:nope) # Raises exception.
|
|
219
|
+
# end
|
|
220
|
+
# end
|
|
221
|
+
#
|
|
222
|
+
# ### Querying the Store
|
|
223
|
+
#
|
|
224
|
+
# Use method #key? to determine whether a given key exists:
|
|
225
|
+
#
|
|
226
|
+
# example_store do |store|
|
|
227
|
+
# store.transaction do
|
|
228
|
+
# store.key?(:foo) # => true
|
|
229
|
+
# end
|
|
230
|
+
# end
|
|
231
|
+
#
|
|
232
|
+
# Use method #keys to retrieve keys:
|
|
233
|
+
#
|
|
234
|
+
# example_store do |store|
|
|
235
|
+
# store.transaction do
|
|
236
|
+
# store.keys # => [:foo, :bar, :baz]
|
|
237
|
+
# end
|
|
238
|
+
# end
|
|
239
|
+
#
|
|
240
|
+
# Use method #path to retrieve the path to the store's underlying file; this
|
|
241
|
+
# method may be called from outside a transaction block:
|
|
242
|
+
#
|
|
243
|
+
# store = PStore.new('t.store')
|
|
244
|
+
# store.path # => "t.store"
|
|
245
|
+
#
|
|
246
|
+
# ## Transaction Safety
|
|
247
|
+
#
|
|
248
|
+
# For transaction safety, see:
|
|
249
|
+
#
|
|
250
|
+
# * Optional argument `thread_safe` at method PStore.new.
|
|
251
|
+
# * Attribute #ultra_safe.
|
|
252
|
+
#
|
|
253
|
+
#
|
|
254
|
+
# Needless to say, if you're storing valuable data with PStore, then you should
|
|
255
|
+
# backup the PStore file from time to time.
|
|
256
|
+
#
|
|
257
|
+
# ## An Example Store
|
|
16
258
|
#
|
|
17
259
|
# require "pstore"
|
|
18
260
|
#
|
|
19
|
-
# #
|
|
261
|
+
# # A mock wiki object.
|
|
20
262
|
# class WikiPage
|
|
21
|
-
#
|
|
263
|
+
#
|
|
264
|
+
# attr_reader :page_name
|
|
265
|
+
#
|
|
266
|
+
# def initialize(page_name, author, contents)
|
|
22
267
|
# @page_name = page_name
|
|
23
268
|
# @revisions = Array.new
|
|
24
|
-
#
|
|
25
269
|
# add_revision(author, contents)
|
|
26
270
|
# end
|
|
27
271
|
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
# :author => author,
|
|
33
|
-
# :contents => contents }
|
|
272
|
+
# def add_revision(author, contents)
|
|
273
|
+
# @revisions << {created: Time.now,
|
|
274
|
+
# author: author,
|
|
275
|
+
# contents: contents}
|
|
34
276
|
# end
|
|
35
277
|
#
|
|
36
278
|
# def wiki_page_references
|
|
37
279
|
# [@page_name] + @revisions.last[:contents].scan(/\b(?:[A-Z]+[a-z]+){2,}/)
|
|
38
280
|
# end
|
|
39
281
|
#
|
|
40
|
-
# # ...
|
|
41
282
|
# end
|
|
42
283
|
#
|
|
43
|
-
# #
|
|
44
|
-
# home_page = WikiPage.new(
|
|
45
|
-
#
|
|
284
|
+
# # Create a new wiki page.
|
|
285
|
+
# home_page = WikiPage.new("HomePage", "James Edward Gray II",
|
|
286
|
+
# "A page about the JoysOfDocumentation..." )
|
|
46
287
|
#
|
|
47
|
-
# # then we want to update page data and the index together, or not at all...
|
|
48
288
|
# wiki = PStore.new("wiki_pages.pstore")
|
|
49
|
-
#
|
|
50
|
-
#
|
|
289
|
+
# # Update page data and the index together, or not at all.
|
|
290
|
+
# wiki.transaction do
|
|
291
|
+
# # Store page.
|
|
51
292
|
# wiki[home_page.page_name] = home_page
|
|
52
|
-
# #
|
|
293
|
+
# # Create page index.
|
|
53
294
|
# wiki[:wiki_index] ||= Array.new
|
|
54
|
-
# #
|
|
295
|
+
# # Update wiki index.
|
|
55
296
|
# wiki[:wiki_index].push(*home_page.wiki_page_references)
|
|
56
|
-
# end
|
|
57
|
-
#
|
|
58
|
-
# ### Some time later... ###
|
|
297
|
+
# end
|
|
59
298
|
#
|
|
60
|
-
# #
|
|
61
|
-
# wiki.transaction(true) do
|
|
62
|
-
# wiki.
|
|
63
|
-
#
|
|
64
|
-
#
|
|
299
|
+
# # Read wiki data, setting argument read_only to true.
|
|
300
|
+
# wiki.transaction(true) do
|
|
301
|
+
# wiki.keys.each do |key|
|
|
302
|
+
# puts key
|
|
303
|
+
# puts wiki[key]
|
|
65
304
|
# end
|
|
66
305
|
# end
|
|
67
306
|
#
|
|
68
|
-
# ## Transaction modes
|
|
69
|
-
#
|
|
70
|
-
# By default, file integrity is only ensured as long as the operating system
|
|
71
|
-
# (and the underlying hardware) doesn't raise any unexpected I/O errors. If an
|
|
72
|
-
# I/O error occurs while PStore is writing to its file, then the file will
|
|
73
|
-
# become corrupted.
|
|
74
|
-
#
|
|
75
|
-
# You can prevent this by setting *pstore.ultra_safe = true*. However, this
|
|
76
|
-
# results in a minor performance loss, and only works on platforms that support
|
|
77
|
-
# atomic file renames. Please consult the documentation for `ultra_safe` for
|
|
78
|
-
# details.
|
|
79
|
-
#
|
|
80
|
-
# Needless to say, if you're storing valuable data with PStore, then you should
|
|
81
|
-
# backup the PStore files from time to time.
|
|
82
|
-
#
|
|
83
307
|
class PStore
|
|
84
308
|
public
|
|
85
309
|
|
|
86
310
|
# <!--
|
|
87
311
|
# rdoc-file=lib/pstore.rb
|
|
88
|
-
# - [](
|
|
312
|
+
# - [](key)
|
|
89
313
|
# -->
|
|
90
|
-
#
|
|
91
|
-
#
|
|
314
|
+
# Returns the value for the given `key` if the key exists. `nil` otherwise; if
|
|
315
|
+
# not `nil`, the returned value is an object or a hierarchy of objects:
|
|
316
|
+
#
|
|
317
|
+
# example_store do |store|
|
|
318
|
+
# store.transaction do
|
|
319
|
+
# store[:foo] # => 0
|
|
320
|
+
# store[:nope] # => nil
|
|
321
|
+
# end
|
|
322
|
+
# end
|
|
323
|
+
#
|
|
324
|
+
# Returns `nil` if there is no such key.
|
|
92
325
|
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
326
|
+
# See also [Hierarchical Values](rdoc-ref:PStore@Hierarchical+Values).
|
|
327
|
+
#
|
|
328
|
+
# Raises an exception if called outside a transaction block.
|
|
95
329
|
#
|
|
96
330
|
def []: (untyped name) -> untyped
|
|
97
331
|
|
|
98
332
|
# <!--
|
|
99
333
|
# rdoc-file=lib/pstore.rb
|
|
100
|
-
# - []=(
|
|
334
|
+
# - []=(key, value)
|
|
101
335
|
# -->
|
|
102
|
-
#
|
|
103
|
-
# store file under the root *name*. Assigning to a *name* already in the data
|
|
104
|
-
# store clobbers the old data.
|
|
105
|
-
#
|
|
106
|
-
# ## Example:
|
|
336
|
+
# Creates or replaces the value for the given `key`:
|
|
107
337
|
#
|
|
108
|
-
#
|
|
338
|
+
# example_store do |store|
|
|
339
|
+
# temp.transaction do
|
|
340
|
+
# temp[:bat] = 3
|
|
341
|
+
# end
|
|
342
|
+
# end
|
|
109
343
|
#
|
|
110
|
-
#
|
|
111
|
-
# store.transaction do # begin transaction
|
|
112
|
-
# # load some data into the store...
|
|
113
|
-
# store[:single_object] = "My data..."
|
|
114
|
-
# store[:obj_hierarchy] = { "Kev Jackson" => ["rational.rb", "pstore.rb"],
|
|
115
|
-
# "James Gray" => ["erb.rb", "pstore.rb"] }
|
|
116
|
-
# end # commit changes to data store file
|
|
344
|
+
# See also [Hierarchical Values](rdoc-ref:PStore@Hierarchical+Values).
|
|
117
345
|
#
|
|
118
|
-
#
|
|
119
|
-
# be read-only. It will raise PStore::Error if called at any other time.
|
|
346
|
+
# Raises an exception if called outside a transaction block.
|
|
120
347
|
#
|
|
121
348
|
def []=: (untyped name, untyped value) -> untyped
|
|
122
349
|
|
|
@@ -124,24 +351,11 @@ class PStore
|
|
|
124
351
|
# rdoc-file=lib/pstore.rb
|
|
125
352
|
# - abort()
|
|
126
353
|
# -->
|
|
127
|
-
#
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
#
|
|
131
|
-
# require "pstore"
|
|
132
|
-
#
|
|
133
|
-
# store = PStore.new("data_file.pstore")
|
|
134
|
-
# store.transaction do # begin transaction
|
|
135
|
-
# store[:one] = 1 # this change is not applied, see below...
|
|
136
|
-
# store[:two] = 2 # this change is not applied, see below...
|
|
354
|
+
# Exits the current transaction block, discarding any changes specified in the
|
|
355
|
+
# transaction block. See [Committing or
|
|
356
|
+
# Aborting](rdoc-ref:PStore@Committing+or+Aborting).
|
|
137
357
|
#
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
# store[:three] = 3 # this change is never reached
|
|
141
|
-
# end
|
|
142
|
-
#
|
|
143
|
-
# **WARNING**: This method is only valid in a PStore#transaction. It will
|
|
144
|
-
# raise PStore::Error if called at any other time.
|
|
358
|
+
# Raises an exception if called outside a transaction block.
|
|
145
359
|
#
|
|
146
360
|
def abort: () -> untyped
|
|
147
361
|
|
|
@@ -149,51 +363,52 @@ class PStore
|
|
|
149
363
|
# rdoc-file=lib/pstore.rb
|
|
150
364
|
# - commit()
|
|
151
365
|
# -->
|
|
152
|
-
#
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
# ## Example:
|
|
366
|
+
# Exits the current transaction block, committing any changes specified in the
|
|
367
|
+
# transaction block. See [Committing or
|
|
368
|
+
# Aborting](rdoc-ref:PStore@Committing+or+Aborting).
|
|
156
369
|
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
# store = PStore.new("data_file.pstore")
|
|
160
|
-
# store.transaction do # begin transaction
|
|
161
|
-
# # load some data into the store...
|
|
162
|
-
# store[:one] = 1
|
|
163
|
-
# store[:two] = 2
|
|
164
|
-
#
|
|
165
|
-
# store.commit # end transaction here, committing changes
|
|
166
|
-
#
|
|
167
|
-
# store[:three] = 3 # this change is never reached
|
|
168
|
-
# end
|
|
169
|
-
#
|
|
170
|
-
# **WARNING**: This method is only valid in a PStore#transaction. It will
|
|
171
|
-
# raise PStore::Error if called at any other time.
|
|
370
|
+
# Raises an exception if called outside a transaction block.
|
|
172
371
|
#
|
|
173
372
|
def commit: () -> nil
|
|
174
373
|
|
|
175
374
|
# <!--
|
|
176
375
|
# rdoc-file=lib/pstore.rb
|
|
177
|
-
# - delete(
|
|
376
|
+
# - delete(key)
|
|
178
377
|
# -->
|
|
179
|
-
# Removes
|
|
378
|
+
# Removes and returns the value at `key` if it exists:
|
|
379
|
+
#
|
|
380
|
+
# example_store do |store|
|
|
381
|
+
# store.transaction do
|
|
382
|
+
# store[:bat] = 3
|
|
383
|
+
# store.delete(:bat)
|
|
384
|
+
# end
|
|
385
|
+
# end
|
|
386
|
+
#
|
|
387
|
+
# Returns `nil` if there is no such key.
|
|
180
388
|
#
|
|
181
|
-
#
|
|
182
|
-
# be read-only. It will raise PStore::Error if called at any other time.
|
|
389
|
+
# Raises an exception if called outside a transaction block.
|
|
183
390
|
#
|
|
184
391
|
def delete: (untyped name) -> untyped
|
|
185
392
|
|
|
186
393
|
# <!--
|
|
187
394
|
# rdoc-file=lib/pstore.rb
|
|
188
|
-
# - fetch(
|
|
395
|
+
# - fetch(key, default=PStore::Error)
|
|
189
396
|
# -->
|
|
190
|
-
#
|
|
191
|
-
#
|
|
192
|
-
# data store, your *default* will be returned instead. If you do not specify a
|
|
193
|
-
# default, PStore::Error will be raised if the object is not found.
|
|
397
|
+
# Like #[], except that it accepts a default value for the store. If the `key`
|
|
398
|
+
# does not exist:
|
|
194
399
|
#
|
|
195
|
-
#
|
|
196
|
-
#
|
|
400
|
+
# * Raises an exception if `default` is `PStore::Error`.
|
|
401
|
+
# * Returns the value of `default` otherwise:
|
|
402
|
+
#
|
|
403
|
+
# example_store do |store|
|
|
404
|
+
# store.transaction do
|
|
405
|
+
# store.fetch(:nope, nil) # => nil
|
|
406
|
+
# store.fetch(:nope) # Raises an exception.
|
|
407
|
+
# end
|
|
408
|
+
# end
|
|
409
|
+
#
|
|
410
|
+
#
|
|
411
|
+
# Raises an exception if called outside a transaction block.
|
|
197
412
|
#
|
|
198
413
|
def fetch: (untyped name, ?untyped default) -> untyped
|
|
199
414
|
|
|
@@ -201,18 +416,16 @@ class PStore
|
|
|
201
416
|
# rdoc-file=lib/pstore.rb
|
|
202
417
|
# - path()
|
|
203
418
|
# -->
|
|
204
|
-
# Returns the path to the
|
|
419
|
+
# Returns the string file path used to create the store:
|
|
420
|
+
#
|
|
421
|
+
# store.path # => "flat.store"
|
|
205
422
|
#
|
|
206
423
|
def path: () -> untyped
|
|
207
424
|
|
|
208
425
|
# <!--
|
|
209
426
|
# rdoc-file=lib/pstore.rb
|
|
210
|
-
# - root?(
|
|
427
|
+
# - root?(key)
|
|
211
428
|
# -->
|
|
212
|
-
# Returns true if the supplied *name* is currently in the data store.
|
|
213
|
-
#
|
|
214
|
-
# **WARNING**: This method is only valid in a PStore#transaction. It will
|
|
215
|
-
# raise PStore::Error if called at any other time.
|
|
216
429
|
#
|
|
217
430
|
def root?: (untyped name) -> bool
|
|
218
431
|
|
|
@@ -220,10 +433,6 @@ class PStore
|
|
|
220
433
|
# rdoc-file=lib/pstore.rb
|
|
221
434
|
# - roots()
|
|
222
435
|
# -->
|
|
223
|
-
# Returns the names of all object hierarchies currently in the store.
|
|
224
|
-
#
|
|
225
|
-
# **WARNING**: This method is only valid in a PStore#transaction. It will
|
|
226
|
-
# raise PStore::Error if called at any other time.
|
|
227
436
|
#
|
|
228
437
|
def roots: () -> Array[untyped]
|
|
229
438
|
|
|
@@ -231,44 +440,50 @@ class PStore
|
|
|
231
440
|
# rdoc-file=lib/pstore.rb
|
|
232
441
|
# - transaction(read_only = false) { |pstore| ... }
|
|
233
442
|
# -->
|
|
234
|
-
# Opens a
|
|
235
|
-
#
|
|
443
|
+
# Opens a transaction block for the store. See
|
|
444
|
+
# [Transactions](rdoc-ref:PStore@Transactions).
|
|
236
445
|
#
|
|
237
|
-
#
|
|
238
|
-
#
|
|
239
|
-
# PStore#commit or PStore#abort. See those methods for details about how
|
|
240
|
-
# changes are handled. Raising an uncaught Exception in the block is equivalent
|
|
241
|
-
# to calling PStore#abort.
|
|
446
|
+
# With argument `read_only` as `false`, the block may both read from and write
|
|
447
|
+
# to the store.
|
|
242
448
|
#
|
|
243
|
-
#
|
|
244
|
-
#
|
|
245
|
-
# raise a PStore::Error.
|
|
449
|
+
# With argument `read_only` as `true`, the block may not include calls to
|
|
450
|
+
# #transaction, #[]=, or #delete.
|
|
246
451
|
#
|
|
247
|
-
#
|
|
452
|
+
# Raises an exception if called within a transaction block.
|
|
248
453
|
#
|
|
249
454
|
def transaction: (?untyped read_only) -> untyped
|
|
250
455
|
|
|
251
456
|
# <!-- rdoc-file=lib/pstore.rb -->
|
|
252
|
-
# Whether PStore should do its best to prevent file corruptions, even when
|
|
253
|
-
# unlikely
|
|
254
|
-
# unusual OS filesystem errors. Setting this flag comes at the price in the form
|
|
255
|
-
# of a performance loss.
|
|
457
|
+
# Whether PStore should do its best to prevent file corruptions, even when an
|
|
458
|
+
# unlikely error (such as memory-error or filesystem error) occurs:
|
|
256
459
|
#
|
|
257
|
-
#
|
|
258
|
-
#
|
|
259
|
-
#
|
|
460
|
+
# * `true`: changes are posted by creating a temporary file, writing the
|
|
461
|
+
# updated data to it, then renaming the file to the given #path. File
|
|
462
|
+
# integrity is maintained. Note: has effect only if the filesystem has
|
|
463
|
+
# atomic file rename (as do POSIX platforms Linux, MacOS, FreeBSD and
|
|
464
|
+
# others).
|
|
465
|
+
#
|
|
466
|
+
# * `false` (the default): changes are posted by rewinding the open file and
|
|
467
|
+
# writing the updated data. File integrity is maintained if the filesystem
|
|
468
|
+
# raises no unexpected I/O error; if such an error occurs during a write to
|
|
469
|
+
# the store, the file may become corrupted.
|
|
260
470
|
#
|
|
261
471
|
def ultra_safe: () -> untyped
|
|
262
472
|
|
|
263
473
|
# <!-- rdoc-file=lib/pstore.rb -->
|
|
264
|
-
# Whether PStore should do its best to prevent file corruptions, even when
|
|
265
|
-
# unlikely
|
|
266
|
-
#
|
|
267
|
-
#
|
|
474
|
+
# Whether PStore should do its best to prevent file corruptions, even when an
|
|
475
|
+
# unlikely error (such as memory-error or filesystem error) occurs:
|
|
476
|
+
#
|
|
477
|
+
# * `true`: changes are posted by creating a temporary file, writing the
|
|
478
|
+
# updated data to it, then renaming the file to the given #path. File
|
|
479
|
+
# integrity is maintained. Note: has effect only if the filesystem has
|
|
480
|
+
# atomic file rename (as do POSIX platforms Linux, MacOS, FreeBSD and
|
|
481
|
+
# others).
|
|
268
482
|
#
|
|
269
|
-
#
|
|
270
|
-
#
|
|
271
|
-
#
|
|
483
|
+
# * `false` (the default): changes are posted by rewinding the open file and
|
|
484
|
+
# writing the updated data. File integrity is maintained if the filesystem
|
|
485
|
+
# raises no unexpected I/O error; if such an error occurs during a write to
|
|
486
|
+
# the store, the file may become corrupted.
|
|
272
487
|
#
|
|
273
488
|
def ultra_safe=: (untyped) -> untyped
|
|
274
489
|
|
|
@@ -311,11 +526,20 @@ class PStore
|
|
|
311
526
|
# rdoc-file=lib/pstore.rb
|
|
312
527
|
# - new(file, thread_safe = false)
|
|
313
528
|
# -->
|
|
314
|
-
#
|
|
315
|
-
#
|
|
529
|
+
# Returns a new PStore object.
|
|
530
|
+
#
|
|
531
|
+
# Argument `file` is the path to the file in which objects are to be stored; if
|
|
532
|
+
# the file exists, it should be one that was written by PStore.
|
|
533
|
+
#
|
|
534
|
+
# path = 't.store'
|
|
535
|
+
# store = PStore.new(path)
|
|
536
|
+
#
|
|
537
|
+
# A PStore object is
|
|
538
|
+
# [reentrant](https://en.wikipedia.org/wiki/Reentrancy_(computing)). If argument
|
|
539
|
+
# `thread_safe` is given as `true`, the object is also thread-safe (at the cost
|
|
540
|
+
# of a small performance penalty):
|
|
316
541
|
#
|
|
317
|
-
# PStore
|
|
318
|
-
# it will become thread-safe at the cost of a minor performance hit.
|
|
542
|
+
# store = PStore.new(path, true)
|
|
319
543
|
#
|
|
320
544
|
def initialize: (untyped file, ?boolish thread_safe) -> untyped
|
|
321
545
|
|