qwe 0.0.0 → 0.0.1
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/DOCS.md +6 -3
- data/README.md +8 -0
- data/exe/qwe +1 -1
- data/lib/qwe/attribute.rb +6 -47
- data/lib/qwe/proxy/array.rb +29 -0
- data/lib/qwe/proxy/hash.rb +28 -0
- data/lib/qwe/proxy.rb +43 -0
- data/lib/qwe/version.rb +1 -1
- data/lib/qwe.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47af0803616e55171f1a450977dd4b72b1b94d8175b89609902a504b5289b1e3
|
4
|
+
data.tar.gz: 74c203d62db281e90db12badbe71f61bc01e3048b8d823005e035adb61658084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 793f496b7be56bd4c51f0954a9a9755d079cf4d76be1bf4f9fba2de584abfd3c5fdaf32297652a95c5ce96eb3fd0686743e583bcec56989e42adbf903cfd9165
|
7
|
+
data.tar.gz: efb62e30e52a37ddaf36d0de164ab65be87e307115ac5325ad1ff6131e35ef31f3257512a4d57ce41ebe9675721e78fe4b9ef13a543651a2b5bb36c355b77f8b
|
data/DOCS.md
CHANGED
@@ -46,6 +46,8 @@ Configuration of server started from puma is done with `config/qwe.yml`. Valid c
|
|
46
46
|
are last variants of cli argument names. For example, detach timeout can be set with
|
47
47
|
`-s`, `--detach` and `--detach_timeout` cli options, or `detach_timeout` config key.
|
48
48
|
|
49
|
+
`--watch` is not available in puma plugin.
|
50
|
+
|
49
51
|
## Production example
|
50
52
|
|
51
53
|
config/puma.rb
|
@@ -219,7 +221,7 @@ multi-line, so it isn't equal to commits count.
|
|
219
221
|
- `commit(str)` - write string to commits file. Attributes do that for you.
|
220
222
|
- `object_at(line)` - returns historic object state, or wayback, by evaluating commits until `line` in context of initial object state.
|
221
223
|
- `fork(line)` - same as object_at, but creates a new record. Returns newly created `Qwe::DB::Record`.
|
222
|
-
- `archive!` - compress commits file with `zst`.
|
224
|
+
- `archive!` - compress commits file with `zst`. If commit is written into archived record, file will get unpacked with a warning.
|
223
225
|
- `dir` - path to the record directory in filesystem
|
224
226
|
- `dump` - `Marshal.dump(object)`
|
225
227
|
|
@@ -266,7 +268,8 @@ attribute :zxc, init: -> { Time.now }
|
|
266
268
|
attribute :qwe, min: 10
|
267
269
|
attribute :asd, max: 20
|
268
270
|
```
|
269
|
-
- `array` - `bool` - initializes attribute to `Qwe::
|
271
|
+
- `array` - `bool` - initializes attribute to `Qwe::Proxy::Array`, which is like array, but commits changes, see [limitations](#Limitations) on why it matters.
|
272
|
+
- `hash` - `bool` - same as array, but for hashes. Attribute type is `Qwe::Proxy::Hash`.
|
270
273
|
- `enum` - `Array` or any object responding to `include?` - raise on write if value is not included in provided enum.
|
271
274
|
```ruby
|
272
275
|
attribute :weather, enum: [:hot, :cold, :normal]
|
@@ -433,7 +436,7 @@ As we expect, resulting `a.str` value would be "qxe". However, `sub!` modifies s
|
|
433
436
|
a.str = a.str.sub "w", "x"
|
434
437
|
```
|
435
438
|
|
436
|
-
For strings this is somewhat fine, but for large arrays things get worse. For arrays there is `Qwe::
|
439
|
+
For strings this is somewhat fine, but for large arrays things get worse. For arrays there is `Qwe::Proxy::Array` class, which extends `Array` class and commits changes.
|
437
440
|
|
438
441
|
So the rule here is **don't use in-place modifications on attributes**, and if you need these - extend desired class and write committing logic. Be sure to benchmark results - sometimes replacing object entirely would be faster than doing complex checks.
|
439
442
|
|
data/README.md
CHANGED
@@ -5,6 +5,14 @@ as possible on the way you write code.
|
|
5
5
|
|
6
6
|
[Full Documentation](DOCS.md)
|
7
7
|
|
8
|
+
[Multiplayer paint example](https://gitlab.com/goose3228/qwe-paint)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Qwe requires native [zstd](https://github.com/facebook/zstd) support.
|
13
|
+
|
14
|
+
Otherwise it's regular `bundle add qwe` or `gem install qwe`
|
15
|
+
|
8
16
|
## Features
|
9
17
|
|
10
18
|
### Zero-config startup
|
data/exe/qwe
CHANGED
data/lib/qwe/attribute.rb
CHANGED
@@ -134,60 +134,19 @@ module Qwe
|
|
134
134
|
end
|
135
135
|
|
136
136
|
add(:array) do
|
137
|
-
writer.stage "value = Qwe::
|
137
|
+
writer.stage "value = Qwe::Proxy::Array.from_array(self, :#{name}, value)"
|
138
138
|
klass.init.stage("self.#{name} = []") unless init
|
139
139
|
end
|
140
140
|
|
141
|
+
add(:hash) do
|
142
|
+
writer.stage "value = Qwe::Proxy::Hash.from_hash(self, :#{name}, value)"
|
143
|
+
klass.init.stage("self.#{name} = {}") unless init
|
144
|
+
end
|
145
|
+
|
141
146
|
add(:enum) do
|
142
147
|
raise "#{klass}.#{name} - enum #{enum} doesn't respond to include?" unless enum.respond_to?(:include?)
|
143
148
|
klass.class_variable_set(:"@@#{name}_enum", enum)
|
144
149
|
writer.stage "raise \"Enum - unknown value \#{self}.#{name} = \#{value}\" unless @@#{name}_enum.include?(value)"
|
145
150
|
end
|
146
|
-
|
147
|
-
class ArrayProxy < Array
|
148
|
-
attr_accessor :__qwe_thing
|
149
|
-
attr_accessor :__qwe_name
|
150
|
-
|
151
|
-
include DRb::DRbUndumped
|
152
|
-
|
153
|
-
undef _dump
|
154
|
-
|
155
|
-
def __qwe_commit(m, *a, **k)
|
156
|
-
__qwe_thing&.root&.record&.commit("#{__qwe_thing.to_rb}.#{__qwe_name}.method(:#{m}).super_method.call(*#{a.to_rb}, **#{k.to_rb})\n")
|
157
|
-
end
|
158
|
-
|
159
|
-
TRANSACTION_METHODS = [:<<, :[]=, :clear, :compact!, :concat, :delete_at, :flatten!, :insert, :pop, :push, :replace, :reverse!, :rotate!, :shift, :shuffle!, :slice!, :unshift]
|
160
|
-
REPLACE_METHODS = [:delete, :delete_if, :fill, :filter!, :select!, :keep_if, :map!, :reject!, :sort!, :sort_by!, :uniq!]
|
161
|
-
|
162
|
-
TRANSACTION_METHODS.each do |m|
|
163
|
-
define_method(m) do |*a, **k|
|
164
|
-
__qwe_commit(m, *a, **k)
|
165
|
-
super(*a, **k)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
REPLACE_METHODS.each do |m|
|
170
|
-
define_method(m) do |*a, **k, &block|
|
171
|
-
r = super(*a, **k, &block)
|
172
|
-
if block
|
173
|
-
__qwe_thing&.root&.record&.commit "#{__qwe_thing.to_rb}.instance_variable_set(:@#{__qwe_name}, #{to_rb})\n"
|
174
|
-
else
|
175
|
-
__qwe_commit(m, *a, **k)
|
176
|
-
end
|
177
|
-
r
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def self.from_array(thing, name, arr = [])
|
182
|
-
a = new(arr)
|
183
|
-
a.__qwe_thing = thing
|
184
|
-
a.__qwe_name = name
|
185
|
-
a
|
186
|
-
end
|
187
|
-
|
188
|
-
def to_rb
|
189
|
-
"Qwe::Attribute::ArrayProxy.from_array(#{__qwe_thing.to_rb}, :#{__qwe_name}, #{super})"
|
190
|
-
end
|
191
|
-
end
|
192
151
|
end
|
193
152
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Qwe::Proxy::Array < Array
|
4
|
+
Qwe::Proxy.make self
|
5
|
+
|
6
|
+
Qwe::Proxy.transaction self,
|
7
|
+
:<<, :[]=, :clear, :compact!, :concat, :delete_at, :flatten!,
|
8
|
+
:insert, :pop, :push, :replace, :reverse!, :rotate!, :shift,
|
9
|
+
:shuffle!, :slice!, :unshift
|
10
|
+
|
11
|
+
Qwe::Proxy.block self,
|
12
|
+
:delete, :delete_if, :fill, :filter!, :select!, :keep_if,
|
13
|
+
:map!, :reject!, :sort!, :sort_by!, :uniq!
|
14
|
+
|
15
|
+
def self.from_array(thing, name, arr = [])
|
16
|
+
if arr.is_a?(Qwe::Proxy::Array)
|
17
|
+
arr
|
18
|
+
else
|
19
|
+
a = new(arr)
|
20
|
+
a.__qwe_thing = thing
|
21
|
+
a.__qwe_name = name
|
22
|
+
a
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_rb
|
27
|
+
"Qwe::Proxy::Array.from_array(#{__qwe_thing.to_rb}, :#{__qwe_name}, #{super})"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Qwe::Proxy::Hash < Hash
|
4
|
+
Qwe::Proxy.make self
|
5
|
+
|
6
|
+
Qwe::Proxy.transaction self,
|
7
|
+
:[]=, :store, :clear, :compact!, :default=, :rehash, :replace, :shift
|
8
|
+
|
9
|
+
Qwe::Proxy.block self,
|
10
|
+
:delete, :delete_if, :filter!, :select!, :keep_if, :merge!,
|
11
|
+
:reject!, :transform_keys!, :transform_values!
|
12
|
+
|
13
|
+
def self.from_hash(thing, name, hash = {})
|
14
|
+
if hash.is_a?(Qwe::Proxy::Hash)
|
15
|
+
hash
|
16
|
+
else
|
17
|
+
h = new
|
18
|
+
h.replace(hash)
|
19
|
+
h.__qwe_thing = thing
|
20
|
+
h.__qwe_name = name
|
21
|
+
h
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_rb
|
26
|
+
"Qwe::Proxy::Hash.from_hash(#{__qwe_thing.to_rb}, :#{__qwe_name}, #{super})"
|
27
|
+
end
|
28
|
+
end
|
data/lib/qwe/proxy.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Qwe
|
2
|
+
module Proxy
|
3
|
+
def self.make(klass)
|
4
|
+
klass.module_exec do
|
5
|
+
attr_accessor :__qwe_thing, :__qwe_name
|
6
|
+
|
7
|
+
include DRb::DRbUndumped
|
8
|
+
|
9
|
+
undef _dump
|
10
|
+
|
11
|
+
def __qwe_commit(m, *a, **k)
|
12
|
+
__qwe_thing&.root&.record&.commit("#{__qwe_thing.to_rb}.#{__qwe_name}.method(:#{m}).super_method.call(*#{a.to_rb}, **#{k.to_rb})\n")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.transaction(klass, *methods)
|
18
|
+
methods.each do |m|
|
19
|
+
klass.define_method(m) do |*a, **k|
|
20
|
+
__qwe_commit(m, *a, **k)
|
21
|
+
super(*a, **k)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.block(klass, *methods)
|
27
|
+
methods.each do |m|
|
28
|
+
klass.define_method(m) do |*a, **k, &block|
|
29
|
+
r = super(*a, **k, &block)
|
30
|
+
if block
|
31
|
+
__qwe_thing&.root&.record&.commit "#{__qwe_thing.to_rb}.instance_variable_set(:@#{__qwe_name}, #{to_rb})\n"
|
32
|
+
else
|
33
|
+
__qwe_commit(m, *a, **k)
|
34
|
+
end
|
35
|
+
r
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
require_relative "proxy/array"
|
43
|
+
require_relative "proxy/hash"
|
data/lib/qwe/version.rb
CHANGED
data/lib/qwe.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qwe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- goose3228
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: drb
|
@@ -68,6 +68,9 @@ files:
|
|
68
68
|
- lib/qwe/mixins/process.rb
|
69
69
|
- lib/qwe/mixins/root.rb
|
70
70
|
- lib/qwe/mixins/thing.rb
|
71
|
+
- lib/qwe/proxy.rb
|
72
|
+
- lib/qwe/proxy/array.rb
|
73
|
+
- lib/qwe/proxy/hash.rb
|
71
74
|
- lib/qwe/version.rb
|
72
75
|
- lib/spawn_worker.rb
|
73
76
|
- qwe.gemspec
|