dddr 2.3.0 → 2.5.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/lib/dddr/sdbm.rb +5 -7
- data/lib/dddr/sequel.rb +39 -60
- data/lib/dddr/version.rb +1 -1
- data/lib/dddr.rb +2 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f96ffac1e23446ac9a1c36f4510843e4dc1604def5358f57118ace997c0b7d82
|
4
|
+
data.tar.gz: f2596ac36f26e0f507b1e0daaf26de0fff2708a840eca88b5ea11b433dbb4f4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea1ff7abff2d883c5a0fc4ede0f79a8895a062e47832372cdbe4303ce111280c032bb2824a84f8d1bbd538d6b45f5ee9ecc2c3d49e193221211ca8bbca4d55c4
|
7
|
+
data.tar.gz: feca838ebd27c5a28169babab509a6278cc485f81b1de1e8f3b96ae327bdb428ad9887640cd786ce0d127d22f2e300b4b34df0aba6ad2eaff792a1a058d0933d
|
data/lib/dddr/sdbm.rb
CHANGED
@@ -168,13 +168,11 @@ module Dddr
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def from_hash(uid, data_hash)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
send(:"#{attribute}=", value)
|
177
|
-
end
|
171
|
+
self.uid = uid
|
172
|
+
data_hash&.each do |attribute, value|
|
173
|
+
attribute = attribute.to_sym
|
174
|
+
if respond_to?(:"#{attribute}=")
|
175
|
+
send(:"#{attribute}=", value)
|
178
176
|
end
|
179
177
|
end
|
180
178
|
end
|
data/lib/dddr/sequel.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
require "sequel"
|
2
|
+
require "securerandom"
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
# Assuming Dddr.configuration.db is already set up to return a Sequel database connection
|
5
5
|
module Dddr
|
6
6
|
module Sequel
|
7
7
|
module ClassMethods
|
8
8
|
def create_properties(*names)
|
9
|
-
names.each do |name|
|
10
|
-
|
11
|
-
attr_accessor name
|
12
|
-
end
|
9
|
+
names.flatten.each do |name|
|
10
|
+
attr_accessor name
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
@@ -20,8 +18,8 @@ module Dddr
|
|
20
18
|
end
|
21
19
|
|
22
20
|
def table(name = nil)
|
23
|
-
|
24
|
-
|
21
|
+
@table_name = name unless name.nil?
|
22
|
+
@table_name
|
25
23
|
end
|
26
24
|
|
27
25
|
def queries(&block)
|
@@ -41,13 +39,12 @@ module Dddr
|
|
41
39
|
|
42
40
|
def create_repository_for(entity_class)
|
43
41
|
repository_class = Class.new(RepositoryBase) do
|
44
|
-
define_singleton_method(:
|
45
|
-
|
42
|
+
define_singleton_method(:entity_class) do
|
43
|
+
entity_class
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
47
|
repository_class.include(@queries_module) if instance_variable_defined?(:@queries_module)
|
50
|
-
|
51
48
|
const_set(:Repository, repository_class)
|
52
49
|
end
|
53
50
|
end
|
@@ -55,79 +52,61 @@ module Dddr
|
|
55
52
|
class RepositoryBase
|
56
53
|
attr_reader :dataset
|
57
54
|
|
58
|
-
def initialize
|
59
|
-
@
|
60
|
-
|
61
|
-
@entity_class.create_properties(@dataset.columns)
|
55
|
+
def initialize
|
56
|
+
@dataset = Dddr.configuration.db[self.class.entity_class.table]
|
57
|
+
self.class.entity_class.create_properties(@dataset.columns)
|
62
58
|
end
|
63
59
|
|
64
60
|
def count
|
65
61
|
@dataset.count
|
66
62
|
end
|
67
63
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
@dataset.insert(entity.to_hash)
|
72
|
-
uid
|
64
|
+
def get(uid)
|
65
|
+
row = @dataset.where(uid: uid).first
|
66
|
+
self.class.entity_class.from_row(row) if row
|
73
67
|
end
|
74
|
-
alias_method :create, :add
|
75
|
-
alias_method :insert, :add
|
76
68
|
|
77
69
|
def update(entity)
|
78
70
|
@dataset.where(uid: entity.uid).update(entity.to_hash)
|
79
71
|
end
|
80
72
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
alias_method :revise, :update
|
85
|
-
alias_method :alter, :update
|
73
|
+
def all
|
74
|
+
@dataset.map { |row| self.class.entity_class.from_row(row) }
|
75
|
+
end
|
86
76
|
|
87
77
|
def delete(entity)
|
88
78
|
@dataset.where(uid: entity.uid).delete
|
89
79
|
end
|
80
|
+
|
81
|
+
alias_method :find, :get
|
90
82
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
def get(uid)
|
98
|
-
row = @dataset.where(uid: uid).first
|
99
|
-
raise Dddr::Error, "UID is required" unless row
|
100
|
-
item = Item.new
|
101
|
-
item.from_hash(uid, row)
|
102
|
-
item
|
83
|
+
def add(entity)
|
84
|
+
uid = SecureRandom.uuid
|
85
|
+
entity.uid = uid
|
86
|
+
@dataset.insert(entity.to_hash)
|
87
|
+
uid
|
103
88
|
end
|
89
|
+
alias_method :create, :add
|
90
|
+
alias_method :insert, :add
|
104
91
|
|
105
|
-
|
92
|
+
# Methods update, delete, get, etc., remain unchanged.
|
93
|
+
end
|
106
94
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
item.from_hash(row[:uid], row)
|
111
|
-
item
|
112
|
-
end
|
95
|
+
module Entity
|
96
|
+
def self.included(base)
|
97
|
+
base.extend(ClassMethods)
|
113
98
|
end
|
114
|
-
end
|
115
99
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
result[attribute_name] = instance_variable_get(var_name)
|
100
|
+
def to_hash
|
101
|
+
instance_variables.each_with_object({}) do |var, hash|
|
102
|
+
hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
|
103
|
+
end
|
121
104
|
end
|
122
|
-
result
|
123
|
-
end
|
124
105
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
if respond_to?(:"#{attribute}=")
|
130
|
-
send(:"#{attribute}=", value)
|
106
|
+
def from_hash(uid, data_hash)
|
107
|
+
self.uid = uid
|
108
|
+
data_hash.each do |attribute, value|
|
109
|
+
send(:"#{attribute}=", value) if respond_to?(:"#{attribute}=")
|
131
110
|
end
|
132
111
|
end
|
133
112
|
end
|
data/lib/dddr/version.rb
CHANGED
data/lib/dddr.rb
CHANGED
@@ -32,20 +32,15 @@ module Dddr
|
|
32
32
|
|
33
33
|
class Serializer
|
34
34
|
def initialize(engine)
|
35
|
-
@mutex = Mutex.new
|
36
35
|
@engine = engine
|
37
36
|
end
|
38
37
|
|
39
38
|
def dump(obj)
|
40
|
-
@mutex.synchronize do
|
41
39
|
@engine.dump(obj)
|
42
|
-
end
|
43
40
|
end
|
44
41
|
|
45
42
|
def load(obj)
|
46
|
-
@mutex.synchronize do
|
47
43
|
@engine.load(obj)
|
48
|
-
end
|
49
44
|
end
|
50
45
|
end
|
51
46
|
|
@@ -73,10 +68,12 @@ module Dddr
|
|
73
68
|
include Dddr::Sdbm
|
74
69
|
base.extend(Dddr::Sdbm::ClassMethods)
|
75
70
|
end
|
71
|
+
|
76
72
|
if Dddr.configuration.engine == :sequel
|
77
73
|
include Dddr::Sequel
|
78
74
|
base.extend(Dddr::Sequel::ClassMethods)
|
79
75
|
end
|
76
|
+
|
80
77
|
end
|
81
78
|
|
82
79
|
attr_accessor :uid, :created_at, :last_updated_at, :deleted, :deleted_at
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dddr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delaney Burke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sdbm
|