dddr 1.0.6 → 1.1.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/version.rb +1 -1
- data/lib/dddr.rb +110 -123
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46a9b18b953d2365bebe6f55b8772d89489133bbca231e7622318b3e8fd44ed1
|
4
|
+
data.tar.gz: 07fa42336f6a55f867eeb111b459803126aa62fd2dc694c5733fb1bf74a36371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c660616726df5f0a8a6f267c0c303bc77b79323751db7da29e87d18214582c26b6977cc243bd75b32ebf64cf1635d159ef16dc642066e13dd4bfa688383ba68b
|
7
|
+
data.tar.gz: 6b333f66013aff5cc3938d199b1d0580d7f350a073304289e20de9afd55c053ee6117b8e0ce5886e9c3cd9896f8c531cd7b7d1a9be9e82b2cf57e8013a73b895
|
data/lib/dddr/version.rb
CHANGED
data/lib/dddr.rb
CHANGED
@@ -30,138 +30,128 @@ module Dddr
|
|
30
30
|
|
31
31
|
module ClassMethods
|
32
32
|
def queries(&block)
|
33
|
-
|
34
|
-
|
33
|
+
@queries_module ||= Module.new
|
34
|
+
@queries_module.module_eval(&block)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
37
|
+
def const_missing(name)
|
38
|
+
if name == :Repository
|
39
|
+
create_repository_for(self)
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
40
43
|
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
@@context = self
|
45
|
+
private
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
def create_repository_for(entity_class)
|
48
|
+
repository_class = Class.new(RepositoryBase) do
|
49
|
+
define_singleton_method(:new) do |*args|
|
50
|
+
super(entity_class)
|
51
|
+
end
|
48
52
|
end
|
49
53
|
|
50
|
-
if
|
54
|
+
repository_class.include(@queries_module) if instance_variable_defined?(:@queries_module)
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def add(entity)
|
62
|
-
uid = SecureRandom.uuid
|
63
|
-
entity.uid = uid
|
64
|
-
entity.created_at ||= DateTime.now.to_s
|
65
|
-
entity.last_updated_at ||= entity.created_at
|
66
|
-
|
67
|
-
SDBM.open(@name) do |db|
|
68
|
-
db[uid] = Marshal.dump(entity.to_hash)
|
69
|
-
end
|
70
|
-
uid
|
71
|
-
end
|
72
|
-
|
73
|
-
alias_method :create, :add
|
74
|
-
alias_method :insert, :add
|
75
|
-
alias_method :put, :add
|
76
|
-
alias_method :append, :add
|
77
|
-
alias_method :store, :add
|
78
|
-
|
79
|
-
def update(entity)
|
80
|
-
entity.last_updated_at = DateTime.now.to_s
|
81
|
-
SDBM.open(@name) do |db|
|
82
|
-
db[entity.uid] = Marshal.dump(entity.to_hash)
|
83
|
-
end
|
84
|
-
entity
|
85
|
-
end
|
86
|
-
|
87
|
-
alias_method :modify, :update
|
88
|
-
alias_method :change, :update
|
89
|
-
alias_method :edit, :update
|
90
|
-
alias_method :revise, :update
|
91
|
-
alias_method :alter, :update
|
92
|
-
|
93
|
-
def delete(entity)
|
94
|
-
SDBM.open(@name) do |db|
|
95
|
-
db.delete(entity.uid)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
alias_method :remove, :delete
|
100
|
-
alias_method :erase, :delete
|
101
|
-
alias_method :discard, :delete
|
102
|
-
alias_method :destroy, :delete
|
103
|
-
alias_method :wipe, :delete
|
104
|
-
|
105
|
-
def get(uid)
|
106
|
-
all.find { |e| e.uid == uid }
|
107
|
-
end
|
108
|
-
|
109
|
-
alias_method :fetch, :get
|
110
|
-
alias_method :retrieve, :get
|
111
|
-
alias_method :find, :get
|
112
|
-
alias_method :acquire, :get
|
113
|
-
alias_method :obtain, :get
|
114
|
-
|
115
|
-
def reset!
|
116
|
-
if Dddr.configuration.env == "test"
|
117
|
-
all.map { |e| delete(e) }
|
118
|
-
return
|
119
|
-
end
|
120
|
-
|
121
|
-
puts "Warning: This will delete all records. Are you sure? (y/n)"
|
122
|
-
confirmation = gets.chomp
|
123
|
-
|
124
|
-
if confirmation.downcase == "y"
|
125
|
-
puts "Type 'reset' to confirm."
|
126
|
-
final_confirmation = gets.chomp
|
127
|
-
|
128
|
-
if final_confirmation.downcase == "reset"
|
129
|
-
all.map { |e| delete(e) }
|
130
|
-
puts "All records have been deleted."
|
131
|
-
else
|
132
|
-
puts "Reset cancelled."
|
133
|
-
end
|
134
|
-
else
|
135
|
-
puts "Reset cancelled."
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def count
|
140
|
-
all.count
|
141
|
-
end
|
142
|
-
|
143
|
-
def all
|
144
|
-
result = []
|
145
|
-
SDBM.open(@name) do |db|
|
146
|
-
db.each do |key, value|
|
147
|
-
entity = @entity_class.new
|
148
|
-
entity.from_hash(key, Marshal.load(value))
|
149
|
-
result << entity unless entity.deleted
|
150
|
-
end
|
151
|
-
end
|
152
|
-
result
|
153
|
-
end
|
154
|
-
end
|
56
|
+
const_set(:Repository, repository_class)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class RepositoryBase
|
61
|
+
def initialize(entity_class)
|
62
|
+
@entity_class = entity_class
|
63
|
+
setup_data_directory(entity_class)
|
64
|
+
end
|
155
65
|
|
156
|
-
|
157
|
-
|
66
|
+
def setup_data_directory(entity_class)
|
67
|
+
env = Dddr.configuration.env
|
68
|
+
data_dir = Dddr.configuration.data_dir
|
69
|
+
container = Dddr.configuration.container
|
70
|
+
unless Dir.exist?(data_dir)
|
71
|
+
if data_dir.include?("/var/")
|
72
|
+
`sudo mkdir -p #{data_dir}/#{container}/#{env}/`
|
73
|
+
`sudo chown $USER #{data_dir}/#{container}/#{env}/`
|
74
|
+
else
|
75
|
+
`mkdir -p #{data_dir}/#{container}/#{env}/`
|
158
76
|
end
|
77
|
+
end
|
78
|
+
@name = "#{data_dir}/#{container}/#{env}/#{entity_class.name.downcase}"
|
79
|
+
end
|
159
80
|
|
160
|
-
|
161
|
-
|
162
|
-
|
81
|
+
def count
|
82
|
+
all.count
|
83
|
+
end
|
84
|
+
|
85
|
+
def add(entity)
|
86
|
+
uid = SecureRandom.uuid
|
87
|
+
entity.uid = uid
|
88
|
+
entity.created_at ||= DateTime.now.to_s
|
89
|
+
entity.last_updated_at ||= entity.created_at
|
90
|
+
|
91
|
+
SDBM.open(@name) do |db|
|
92
|
+
db[uid] = Marshal.dump(entity.to_hash)
|
93
|
+
end
|
94
|
+
uid
|
95
|
+
end
|
96
|
+
|
97
|
+
alias_method :create, :add
|
98
|
+
alias_method :insert, :add
|
99
|
+
alias_method :put, :add
|
100
|
+
alias_method :append, :add
|
101
|
+
alias_method :store, :add
|
102
|
+
|
103
|
+
def update(entity)
|
104
|
+
return unless entity.uid
|
105
|
+
entity.last_updated_at = DateTime.now.to_s
|
106
|
+
SDBM.open(@name) do |db|
|
107
|
+
db[entity.uid] = Marshal.dump(entity.to_hash)
|
108
|
+
end
|
109
|
+
entity
|
110
|
+
end
|
111
|
+
|
112
|
+
alias_method :modify, :update
|
113
|
+
alias_method :change, :update
|
114
|
+
alias_method :edit, :update
|
115
|
+
alias_method :revise, :update
|
116
|
+
alias_method :alter, :update
|
117
|
+
|
118
|
+
def delete(entity)
|
119
|
+
return unless entity.uid
|
120
|
+
SDBM.open(@name) do |db|
|
121
|
+
db.delete(entity.uid)
|
163
122
|
end
|
164
123
|
end
|
124
|
+
|
125
|
+
alias_method :remove, :delete
|
126
|
+
alias_method :erase, :delete
|
127
|
+
alias_method :discard, :delete
|
128
|
+
alias_method :destroy, :delete
|
129
|
+
alias_method :wipe, :delete
|
130
|
+
|
131
|
+
def get(uid)
|
132
|
+
SDBM.open(@name) do |db|
|
133
|
+
data = db[uid]
|
134
|
+
return unless data
|
135
|
+
|
136
|
+
entity = @entity_class.new
|
137
|
+
entity.from_hash(uid, Marshal.load(data))
|
138
|
+
entity
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
alias_method :find, :get
|
143
|
+
|
144
|
+
def all
|
145
|
+
result = []
|
146
|
+
SDBM.open(@name) do |db|
|
147
|
+
db.each do |key, value|
|
148
|
+
entity = @entity_class.new
|
149
|
+
entity.from_hash(key, Marshal.load(value))
|
150
|
+
result << entity unless entity.deleted
|
151
|
+
end
|
152
|
+
end
|
153
|
+
result
|
154
|
+
end
|
165
155
|
end
|
166
156
|
|
167
157
|
def to_hash
|
@@ -174,8 +164,7 @@ module Dddr
|
|
174
164
|
end
|
175
165
|
|
176
166
|
def new?
|
177
|
-
|
178
|
-
false
|
167
|
+
created_at.nil?
|
179
168
|
end
|
180
169
|
|
181
170
|
def from_hash(uid, data_hash)
|
@@ -188,8 +177,6 @@ module Dddr
|
|
188
177
|
end
|
189
178
|
end
|
190
179
|
end
|
191
|
-
|
192
|
-
# Your code goes here...
|
193
180
|
end
|
194
181
|
|
195
182
|
Dddr.configure
|
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: 1.0
|
4
|
+
version: 1.1.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:
|
11
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sdbm
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.5.3
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Domain Driven Design Repository
|