gembase 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/main.rb +58 -71
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b2075c49a96fb7cfb47f1b1dcc0ce4990426d34899dbe5a6fb4e26bb3d89624
|
4
|
+
data.tar.gz: 7fe0747e86e9a39a03ad3aaf437ff26eeccac21fbbb5965759bc5caa2f54c6ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d318c786331cbfa72a0126dad32ae42197a62358ed1caaeee2ea7351ce41df3df366831f3ad67f7b5a2c45b2da05df8b0c94534875fa7b83ea56fda76892de52
|
7
|
+
data.tar.gz: e664207015a063c5d81c4721baf506e5ed737ebd579ab5baa8470f97dc7d9d112d7492ad8b8961c8df16b85b444fd6288fff5bf7ad07848bba16eadfbc2a80db
|
data/lib/main.rb
CHANGED
@@ -2,28 +2,25 @@
|
|
2
2
|
# NTBBloodbath | Gembase - Ruby DataBase
|
3
3
|
|
4
4
|
require 'yaml'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
7
|
# @author NTBBloodbath
|
7
8
|
module Gembase
|
8
9
|
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param name [String] the name for your DataBase file
|
10
|
+
# Create a new DataBase file with the given name.
|
11
|
+
# name must be an String.
|
12
12
|
#
|
13
|
-
#
|
14
|
-
# create_db("example") #=> "example.rudb"
|
13
|
+
# create_db("example") #=> "example.rudb"
|
15
14
|
def Gembase.create_db(name)
|
16
15
|
raise "name must be an String" until name.is_a?(String)
|
17
16
|
FileUtils.touch("#{name}.rudb")
|
18
17
|
end
|
19
18
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# @param category [String] the name of your category
|
19
|
+
# Create a new Category inside our DataBase
|
20
|
+
# db must be an String.
|
21
|
+
# category must be an String.
|
24
22
|
#
|
25
|
-
#
|
26
|
-
# create_category("example", "users")
|
23
|
+
# create_category("example", "foo")
|
27
24
|
def Gembase.create_category(db, category)
|
28
25
|
raise "db must be an String" until db.is_a?(String)
|
29
26
|
raise "category must be an String" until category.is_a?(String)
|
@@ -37,16 +34,12 @@ module Gembase
|
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
# @param nested_category [String] the name of the nested category
|
37
|
+
# Create a new nested category
|
38
|
+
# db must be an String.
|
39
|
+
# parent_category must be an String.
|
40
|
+
# nested_category must be an String.
|
45
41
|
#
|
46
|
-
#
|
47
|
-
# nested_category("example", "users", "premium")
|
48
|
-
#
|
49
|
-
# @since 0.5.0
|
42
|
+
# nested_category("example", "foo", "bar")
|
50
43
|
def Gembase.nested_category(db, parent_category, nested_category)
|
51
44
|
raise "db must be an String" until db.is_a?(String)
|
52
45
|
raise "parent_category must be an String" until parent_category.is_a?(String)
|
@@ -58,17 +51,15 @@ module Gembase
|
|
58
51
|
@save = File.write(@database, @data.to_yaml)
|
59
52
|
end
|
60
53
|
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# @param value [String, Integer, Boolean] the value of your key
|
54
|
+
# Create an object inside a category
|
55
|
+
# db must be an String.
|
56
|
+
# category must be an String.
|
57
|
+
# key must be an String.
|
58
|
+
# value can be String, Integer or Boolean.
|
67
59
|
#
|
68
|
-
#
|
69
|
-
# add_object("example", "users", "bloodbath", "premium")
|
60
|
+
# add_object("example", "users", "bloodbath", "premium")
|
70
61
|
#
|
71
|
-
#
|
62
|
+
# [DEPRECATED] Use create_object Method instead.
|
72
63
|
def Gembase.add_object(db, category, key, value)
|
73
64
|
raise "db must be an String" until db.is_a?(String)
|
74
65
|
raise "category must be an String" until category.is_a?(String)
|
@@ -80,21 +71,20 @@ module Gembase
|
|
80
71
|
@data["#{category}"].store("#{key}", "#{value}")
|
81
72
|
end
|
82
73
|
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# @example Create object "server" with value "localhost:8080". Without categories.
|
74
|
+
# Create an object outside a category
|
75
|
+
# db must be an String.
|
76
|
+
# key must be an String.
|
77
|
+
# value can be String, Integer or Boolean.
|
78
|
+
# category must be an String.
|
79
|
+
# subcategory must be an String.
|
80
|
+
#
|
81
|
+
# Create object "server" with value "localhost:8080". Without categories.
|
92
82
|
# create_object("example", "server", "localhost:8080")
|
93
83
|
#
|
94
|
-
#
|
84
|
+
# Create object "users-limit" with value 5 in "users" category.
|
95
85
|
# create_object("example", "users-limit", 5, "users")
|
96
86
|
#
|
97
|
-
#
|
87
|
+
# Create object "bloodbath" with value true in "premium" subcategory.
|
98
88
|
# create_object("example", "bloodbath", true, "users", "premium")
|
99
89
|
def Gembase.create_object(db, key, value, category=nil, subcategory=nil)
|
100
90
|
raise "db must be an String" until db.is_a?(String)
|
@@ -123,27 +113,27 @@ module Gembase
|
|
123
113
|
end
|
124
114
|
|
125
115
|
# @!method delete_object(db, key, category=nil, subcategory=nil)
|
126
|
-
# Delete an object inside/outside a category.
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
116
|
+
# Delete an object inside/outside a category and subcategory.
|
117
|
+
# db must be an String.
|
118
|
+
# key must be an String.
|
119
|
+
# category must be an String.
|
120
|
+
# subcategory must be an String.
|
131
121
|
#
|
132
|
-
#
|
122
|
+
# Deleting object inside a category
|
133
123
|
# delete_object("example", "users-limit", "users")
|
134
124
|
#
|
135
|
-
#
|
125
|
+
# Deleting object inside a subcategory
|
136
126
|
# delete_object("example", "bloodbath", "users", "premium")
|
137
127
|
#
|
138
|
-
#
|
128
|
+
# Deleting object outside a category
|
139
129
|
# delete_object("example", "server")
|
140
130
|
#
|
141
|
-
#
|
131
|
+
# Note: Category and subcategory are an optional parameters. Use them only when you want to delete an object inside a category or subcategory.
|
142
132
|
def Gembase.delete_object(db, key, category=nil, subcategory=nil)
|
143
133
|
raise "db must be an String" until db.is_a?(String)
|
144
134
|
raise "key must be an String" until key.is_a?(String)
|
145
135
|
|
146
|
-
if category.to_s.length == 0
|
136
|
+
if category.to_s.length == 0
|
147
137
|
@database
|
148
138
|
@data
|
149
139
|
@data.delete("#{key}")
|
@@ -151,7 +141,7 @@ module Gembase
|
|
151
141
|
f.write(@data.to_yaml)
|
152
142
|
end
|
153
143
|
else
|
154
|
-
if subcategory.to_s.length == 0
|
144
|
+
if subcategory.to_s.length == 0
|
155
145
|
raise "category must be an String" until category.is_a?(String)
|
156
146
|
@database
|
157
147
|
@data
|
@@ -171,24 +161,23 @@ module Gembase
|
|
171
161
|
end
|
172
162
|
end
|
173
163
|
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
# @param subcategory [String] the name of your subcategory
|
164
|
+
# Change the value of an existing object
|
165
|
+
# db must be an String.
|
166
|
+
# key must be an String.
|
167
|
+
# new_value can be String, Integer or Boolean.
|
168
|
+
# category must be an String.
|
169
|
+
# subcategory must be an String.
|
181
170
|
#
|
182
|
-
#
|
171
|
+
# Change key server value from localhost:8080 to example_host.com outside categories
|
183
172
|
# change_object("example", "server", "example_host.com")
|
184
173
|
#
|
185
|
-
#
|
174
|
+
# Change key users-limit value from 5 to 10 into users category
|
186
175
|
# change_object("example", "users-limit", "10", "users")
|
187
176
|
#
|
188
|
-
#
|
177
|
+
# Change key bloodbath value from true to false into premium subcategory
|
189
178
|
# change_object("example", "bloodbath", false, "users", "category")
|
190
179
|
#
|
191
|
-
#
|
180
|
+
# Note: Category and subcategory are an optional parameters. Use them only when you want to modify an object inside a category or subcategory.
|
192
181
|
def Gembase.change_object(db, key, new_value, category=nil, subcategory=nil)
|
193
182
|
raise "db must be an String" until db.is_a?(String)
|
194
183
|
raise "key must be an String" until key.is_a?(String)
|
@@ -215,14 +204,13 @@ module Gembase
|
|
215
204
|
end
|
216
205
|
end
|
217
206
|
|
218
|
-
#
|
219
|
-
#
|
220
|
-
# @param db [String] the name of your DataBase file
|
207
|
+
# Parse the Database structure to modify it
|
208
|
+
# db must be an String.
|
221
209
|
#
|
222
|
-
#
|
210
|
+
# Parsing the DB called "example"
|
223
211
|
# parse("example")
|
224
212
|
#
|
225
|
-
#
|
213
|
+
# Note: You can use these two methods (parse and generate) instead of YAML vanilla methods (load and to_yaml).
|
226
214
|
def Gembase.parse(db)
|
227
215
|
raise "db must be an String" until db.is_a?(String)
|
228
216
|
|
@@ -230,11 +218,10 @@ module Gembase
|
|
230
218
|
@data
|
231
219
|
end
|
232
220
|
|
233
|
-
#
|
234
|
-
#
|
235
|
-
# @param db [String] the name of your DataBase file
|
221
|
+
# Regenerate the Database stucture to YAML structure
|
222
|
+
# db must be an String.
|
236
223
|
#
|
237
|
-
#
|
224
|
+
# Regenerating the DB called "example"
|
238
225
|
# regenerate("example")
|
239
226
|
def Gembase.regenerate(db)
|
240
227
|
raise "db must be an String" until db.is_a?(String)
|