dddr 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dddr/sequel.rb +46 -63
- data/lib/dddr/version.rb +1 -1
- data/lib/dddr.rb +8 -1
- 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: d7ad39d7137de961ad7d5a3998b4e47acf2e500b18c4c22872d6d4267c921c14
|
4
|
+
data.tar.gz: 482665fcf1eb5722ebf0942c6e521d0f4b673cb51e30378cdb0e72a448997728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5b1958c7a3c414c8a7b2ae32d94f84ca21c615d0752cab9d41676f2cc2edca33d16107235ec52d665ecaed04a9ababa88f855c68a6b7f063ba5cd896aef9584
|
7
|
+
data.tar.gz: c5b55bf5b7f9567999159a528739a24e687afcdbffab569b5b037bf184990eb98cdc47068b83bf4683eabfa27a921029e9e8876905c4e886298e9769f05cf406
|
data/lib/dddr/sequel.rb
CHANGED
@@ -1,6 +1,30 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
::Sequel::Model.plugin :timestamps
|
4
|
+
|
1
5
|
module Dddr
|
2
6
|
module Sequel
|
3
7
|
module ClassMethods
|
8
|
+
|
9
|
+
def create_properties(*names)
|
10
|
+
names.each do |name|
|
11
|
+
name.each do |name|
|
12
|
+
attr_accessor name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def from_row(row)
|
18
|
+
item = new
|
19
|
+
item.from_hash(row[:uid],row)
|
20
|
+
item
|
21
|
+
end
|
22
|
+
|
23
|
+
def table(name = nil)
|
24
|
+
@@table_name = name unless name.nil?
|
25
|
+
@@table_name
|
26
|
+
end
|
27
|
+
|
4
28
|
def queries(&block)
|
5
29
|
@queries_module ||= Module.new
|
6
30
|
@queries_module.module_eval(&block)
|
@@ -30,64 +54,32 @@ module Dddr
|
|
30
54
|
end
|
31
55
|
|
32
56
|
class RepositoryBase
|
57
|
+
|
58
|
+
attr_reader :dataset
|
59
|
+
|
33
60
|
def initialize(entity_class)
|
34
61
|
@entity_class = entity_class
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def setup_data_directory(entity_class)
|
39
|
-
env = Dddr.configuration.env
|
40
|
-
data_dir = Dddr.configuration.data_dir
|
41
|
-
container = Dddr.configuration.container
|
42
|
-
raise Dddr::Error, "Container name is required" unless container
|
43
|
-
|
44
|
-
# Construct the target directory path
|
45
|
-
@name = "#{data_dir}/#{container}/#{env}/#{entity_class.name.downcase}"
|
46
|
-
|
47
|
-
begin
|
48
|
-
# Ensure all directories in the path are created
|
49
|
-
FileUtils.mkdir_p(@name)
|
50
|
-
|
51
|
-
# Change ownership only if the path starts with "/var/"
|
52
|
-
if @name.start_with?("/var/")
|
53
|
-
FileUtils.chown_R(ENV["USER"], nil, @name)
|
54
|
-
end
|
55
|
-
rescue Errno::ENOENT => e
|
56
|
-
# Log or handle the error
|
57
|
-
raise "Failed to create or access the directory: #{e.message}"
|
58
|
-
end
|
62
|
+
@dataset = Dddr.configuration.db[@entity_class.table]
|
63
|
+
@entity_class.create_properties(@dataset.columns)
|
59
64
|
end
|
60
65
|
|
61
66
|
def count
|
62
|
-
|
67
|
+
@dataset.count
|
63
68
|
end
|
64
69
|
|
65
70
|
def add(entity)
|
66
71
|
uid = SecureRandom.uuid
|
67
72
|
entity.uid = uid
|
68
|
-
entity.
|
69
|
-
entity.last_updated_at ||= entity.created_at
|
70
|
-
|
71
|
-
SDBM.open(@name) do |db|
|
72
|
-
db[uid] = Marshal.dump(entity.to_hash)
|
73
|
-
end
|
73
|
+
@dataset.insert(entity.to_hash)
|
74
74
|
uid
|
75
75
|
end
|
76
|
-
|
77
76
|
alias_method :create, :add
|
78
77
|
alias_method :insert, :add
|
79
|
-
alias_method :put, :add
|
80
|
-
alias_method :append, :add
|
81
|
-
alias_method :store, :add
|
82
78
|
|
83
79
|
def update(entity)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
db[entity.uid] = Marshal.dump(entity.to_hash)
|
88
|
-
end
|
89
|
-
entity
|
90
|
-
end
|
80
|
+
@dataset.where(uid: entity.uid).update(entity.to_hash)
|
81
|
+
|
82
|
+
end
|
91
83
|
|
92
84
|
alias_method :modify, :update
|
93
85
|
alias_method :change, :update
|
@@ -96,10 +88,7 @@ module Dddr
|
|
96
88
|
alias_method :alter, :update
|
97
89
|
|
98
90
|
def delete(entity)
|
99
|
-
|
100
|
-
SDBM.open(@name) do |db|
|
101
|
-
db.delete(entity.uid)
|
102
|
-
end
|
91
|
+
@dataset.where(uid: entity.uid).delete
|
103
92
|
end
|
104
93
|
|
105
94
|
alias_method :remove, :delete
|
@@ -109,28 +98,21 @@ module Dddr
|
|
109
98
|
alias_method :wipe, :delete
|
110
99
|
|
111
100
|
def get(uid)
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
entity.from_hash(uid, Marshal.load(data))
|
118
|
-
entity
|
119
|
-
end
|
101
|
+
row = @dataset.where(uid: uid).first
|
102
|
+
raise Dddr::Error, "UID is required" unless row
|
103
|
+
item = Item.new
|
104
|
+
item.from_hash(uid,row)
|
105
|
+
item
|
120
106
|
end
|
121
107
|
|
122
108
|
alias_method :find, :get
|
123
109
|
|
124
110
|
def all
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
entity.from_hash(key, Marshal.load(value))
|
130
|
-
result << entity unless entity.deleted
|
131
|
-
end
|
111
|
+
@dataset.all.map do |row|
|
112
|
+
item = Item.new
|
113
|
+
item.from_hash(row[:uid],row)
|
114
|
+
item
|
132
115
|
end
|
133
|
-
result
|
134
116
|
end
|
135
117
|
end
|
136
118
|
|
@@ -142,7 +124,7 @@ module Dddr
|
|
142
124
|
end
|
143
125
|
result
|
144
126
|
end
|
145
|
-
|
127
|
+
|
146
128
|
def from_hash(uid, data_hash)
|
147
129
|
self.uid = uid
|
148
130
|
data_hash.each do |attribute, value|
|
@@ -152,5 +134,6 @@ module Dddr
|
|
152
134
|
end
|
153
135
|
end
|
154
136
|
end
|
137
|
+
|
155
138
|
end
|
156
139
|
end
|
data/lib/dddr/version.rb
CHANGED
data/lib/dddr.rb
CHANGED
@@ -55,6 +55,13 @@ module Dddr
|
|
55
55
|
class Error < StandardError; end
|
56
56
|
|
57
57
|
module Entity
|
58
|
+
|
59
|
+
def self.create_properties(*names)
|
60
|
+
names.each do |name|
|
61
|
+
attr_accessor name
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
58
65
|
def self.included(base)
|
59
66
|
if Dddr.configuration.engine == :sdbm
|
60
67
|
Dddr::ENTITIES << base
|
@@ -63,7 +70,7 @@ module Dddr
|
|
63
70
|
end
|
64
71
|
if Dddr.configuration.engine == :sequel
|
65
72
|
include Dddr::Sequel
|
66
|
-
base.extend(Dddr::
|
73
|
+
base.extend(Dddr::Sequel::ClassMethods)
|
67
74
|
end
|
68
75
|
end
|
69
76
|
|
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.2.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-02-
|
11
|
+
date: 2024-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sdbm
|