qwe 0.0.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.
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Qwe::Mixins
4
+ module Root
5
+ def things
6
+ @things ||= [self]
7
+ end
8
+
9
+ def [](id)
10
+ @things[id]
11
+ end
12
+
13
+ def create(klass, commit = true, **args)
14
+ thing = (klass.is_a?(Symbol) && Object.const_get(klass) || klass).new
15
+ thing.id = things.length if thing.respond_to?(:id=)
16
+ thing.root = self if thing.respond_to?(:root=)
17
+ if commit
18
+ commit(self, :create, klass, false)
19
+ thing.init if thing.respond_to?(:init)
20
+ end
21
+ args.each do |k, v|
22
+ thing.send(:"#{k}=", v)
23
+ end
24
+ things.push(thing)
25
+ thing
26
+ end
27
+
28
+ def commit(thing, method, *args, **keywords)
29
+ record&.commit "#{thing.to_rb}.#{method}( " +
30
+ (args.map { |a| a.to_rb }).join(", ") +
31
+ (keywords.to_a.map { |a| "#{a[0]}: #{a[1].to_rb}" }).join(", ") + ")\n"
32
+ end
33
+
34
+ Qwe::Mixins.mix(self) do |mod|
35
+ mod.include Qwe::Mixins::Thing
36
+
37
+ mod.attr_accessor :record
38
+
39
+ mod.define_method(:to_rb) { "self" }
40
+
41
+ mod.init.stage("self.root = self")
42
+ mod.init.stage("self.id = 0")
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Qwe::Mixins
4
+ module Thing
5
+ def []=(name, value)
6
+ instance_variable_set(name, value)
7
+ root&.commit(self, :instance_variable_set, name, value)
8
+ end
9
+
10
+ def to_rb
11
+ "self[#{id}]"
12
+ end
13
+
14
+ Qwe::Mixins.mix(self) do |mod|
15
+ mod.attr_accessor :root, :id
16
+
17
+ mod.define_singleton_method(:attributes) do
18
+ Qwe[self, :attributes] || {}
19
+ end
20
+
21
+ mod.define_singleton_method(:attribute) do |name, *args, **keywords|
22
+ Qwe[self, :attributes, name] = Qwe::Attribute.new(self, name, *args, **keywords)
23
+ Qwe[self, :attributes, name].compile
24
+ end
25
+
26
+ mod.define_singleton_method(:init) do
27
+ Qwe[self, :init] ||= Qwe::Function.new(self, :init)
28
+ end
29
+
30
+ mod.include DRb::DRbUndumped
31
+ mod.undef_method :_dump
32
+
33
+ Qwe.define_logger(mod)
34
+ end
35
+ end
36
+ end
data/lib/qwe/mixins.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Qwe::Mixins
4
+ def self.mix(inc, &block)
5
+ inc.define_singleton_method(:included) do |mod|
6
+ if mod.const_defined?(:"INCLUDED_#{inc.to_s.upcase.gsub(/[^A-Z]/, "")}")
7
+ else
8
+ mod.const_set(:"INCLUDED_#{inc.to_s.upcase.gsub(/[^A-Z]/, "")}", true)
9
+ inc.instance_exec(mod, &block)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ require_relative "mixins/process"
16
+ require_relative "mixins/thing"
17
+ require_relative "mixins/root"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Qwe
4
+ VERSION = "0.0.0"
5
+ end
data/lib/qwe.rb ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "drb"
4
+ require "json"
5
+ require "fileutils"
6
+
7
+ require_relative "guerilla"
8
+ require_relative "qwe/version"
9
+ require_relative "qwe/mixins"
10
+ require_relative "qwe/db"
11
+ require_relative "qwe/function"
12
+ require_relative "qwe/attribute"
13
+
14
+ module Qwe
15
+ STORE = {}
16
+
17
+ def self.[](*args)
18
+ v = STORE
19
+ args.each do |a|
20
+ v = v[a]
21
+ return nil if v.nil?
22
+ end
23
+ v
24
+ end
25
+
26
+ def self.[]=(*args)
27
+ value = args.pop
28
+ key = args.pop
29
+ s = STORE
30
+ args.each do |a|
31
+ s[a] ||= {}
32
+ s = s[a]
33
+ end
34
+ s[key] = value
35
+ end
36
+
37
+ def self.log(object, *args, **keywords)
38
+ puts "\e[0;34m#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} \e[1;34m#{Process.pid} \e[0;34m#{object.class}\e[0m " + args.join(", ") + ""
39
+ pp keywords unless keywords.empty?
40
+ end
41
+
42
+ def self.define_logger(klass)
43
+ klass.define_method :log do |*args, **keywords|
44
+ Qwe.log(self, *args, **keywords)
45
+ end
46
+ end
47
+
48
+ [DB::Server, DB::Worker, DB::Record, DB::CommitsFile, Function, Attribute].each { |k| define_logger(k) }
49
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift __dir__
4
+ require "qwe"
5
+ Qwe::DB::Worker.spawn(*ARGV)
data/qwe.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/qwe/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "qwe"
7
+ spec.version = Qwe::VERSION
8
+ spec.authors = ["goose3228"]
9
+ spec.email = ["goose3228@protonmail.com"]
10
+
11
+ spec.summary = "Framework for in-RAM ruby applications"
12
+ spec.description = "Object persistence with DRb access, manual or automatic RAM/disk switch, and transactions as ruby code."
13
+ spec.homepage = "https://gitlab.com/goose3228/qwe"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ spec.metadata["source_code_uri"] = "https://gitlab.com/goose3228/qwe"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "drb", "~> 2.2.1"
31
+ spec.add_dependency "ruby-zstds", "~> 1.3"
32
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qwe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - goose3228
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-12-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: drb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-zstds
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ description: Object persistence with DRb access, manual or automatic RAM/disk switch,
42
+ and transactions as ruby code.
43
+ email:
44
+ - goose3228@protonmail.com
45
+ executables:
46
+ - qwe
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - DOCS.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - exe/qwe
57
+ - lib/guerilla.rb
58
+ - lib/puma/plugin/qwe.rb
59
+ - lib/qwe.rb
60
+ - lib/qwe/attribute.rb
61
+ - lib/qwe/db.rb
62
+ - lib/qwe/db/commits_file.rb
63
+ - lib/qwe/db/record.rb
64
+ - lib/qwe/db/server.rb
65
+ - lib/qwe/db/worker.rb
66
+ - lib/qwe/function.rb
67
+ - lib/qwe/mixins.rb
68
+ - lib/qwe/mixins/process.rb
69
+ - lib/qwe/mixins/root.rb
70
+ - lib/qwe/mixins/thing.rb
71
+ - lib/qwe/version.rb
72
+ - lib/spawn_worker.rb
73
+ - qwe.gemspec
74
+ homepage: https://gitlab.com/goose3228/qwe
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ source_code_uri: https://gitlab.com/goose3228/qwe
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.0.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.5.16
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Framework for in-RAM ruby applications
98
+ test_files: []