gembase 0.1.0.pre → 0.5.1
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 +236 -15
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deb4dbb31cbfe652b4ac768e296bcede2ffdbc19473850786808ec3d34d9a6c6
|
4
|
+
data.tar.gz: af22f113ecff87ed52020d9165db3bb153e72b81477cbe39c700a135afad7e79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0322593fc697d8c40458351f9d512bddccce4e127b94a2f2bbfd4fb06c41aded132e9dc3813dd90774d6bd2454da4b660dd1be359b24fa28283c6ca322ae9c0
|
7
|
+
data.tar.gz: ac2893bae265dbe20e69a9f4eaff05010916ec6c5291a37de3cc52cccee30a785ae8ff4b93c8ee38a2ed6d4b6d023b489c19b5fbe23f4adaffa1930b1ac25f82
|
data/lib/main.rb
CHANGED
@@ -1,24 +1,245 @@
|
|
1
1
|
#!usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# NTBBloodbath | Gembase - Ruby DataBase
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'yaml' # Requires yaml gem
|
4
|
+
require 'yaml'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
# @author NTBBloodbath
|
7
|
+
module Gembase
|
8
|
+
|
9
|
+
# @!method create_db(name) {https://asciinema.org/a/l8CbUREGwZScWN2XJXv2lsTHt}
|
10
|
+
# Create a new DataBase file with the given name
|
11
|
+
# @param name [String] the name for your DataBase file
|
12
|
+
#
|
13
|
+
# @example Create a DB called example
|
14
|
+
# create_db("example") #=> "example.rudb"
|
15
|
+
def Gembase.create_db(name)
|
16
|
+
raise "name must be an String" until name.is_a?(String)
|
17
|
+
FileUtils.touch("#{name}.rudb")
|
12
18
|
end
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
# @!method create_category(db, category) {https://asciinema.org/a/Chz5eeUJdjFl8I07Lq4hY4X8y}
|
21
|
+
# Create a new Category inside our DataBase
|
22
|
+
# @param db [String] the name of your DataBase file
|
23
|
+
# @param category [String] the name of your category
|
24
|
+
#
|
25
|
+
# @example Creating the users category
|
26
|
+
# create_category("example", "users")
|
27
|
+
def Gembase.create_category(db, category)
|
28
|
+
raise "db must be an String" until db.is_a?(String)
|
29
|
+
raise "category must be an String" until category.is_a?(String)
|
30
|
+
|
31
|
+
category_name = {
|
32
|
+
"#{category}" => {}
|
19
33
|
}
|
20
|
-
|
21
|
-
|
34
|
+
|
35
|
+
File.open("#{db}.rudb", "a+") do |f|
|
36
|
+
f.write(category_name.to_yaml)
|
22
37
|
end
|
23
38
|
end
|
39
|
+
|
40
|
+
# @!method nested_category(db, parent_category, nested_category)
|
41
|
+
# Create a new nested category
|
42
|
+
# @param db [String] the nme of your DataBase file
|
43
|
+
# @param parent_category [String] the name of your parent category
|
44
|
+
# @param nested_category [String] the name of the nested category
|
45
|
+
#
|
46
|
+
# @example Creating a premium nested category
|
47
|
+
# nested_category("example", "users", "premium")
|
48
|
+
#
|
49
|
+
# @since 0.5.0
|
50
|
+
def Gembase.nested_category(db, parent_category, nested_category)
|
51
|
+
raise "db must be an String" until db.is_a?(String)
|
52
|
+
raise "parent_category must be an String" until parent_category.is_a?(String)
|
53
|
+
raise "nested_category must be an String" until nested_category.is_a?(String)
|
54
|
+
|
55
|
+
@database = File.open("#{db}.rudb")
|
56
|
+
@data = YAML.load(@database)
|
57
|
+
@data["#{parent_category}"].store("#{nested_category}", "{}")
|
58
|
+
@save = File.write(@database, @data.to_yaml)
|
59
|
+
end
|
60
|
+
|
61
|
+
# @!method add_object(db, category, key, value)
|
62
|
+
# Create an object inside a category
|
63
|
+
# @param db [String] the name of your DataBase file
|
64
|
+
# @param category [String] the name of your category
|
65
|
+
# @param key [String] the key name of your object
|
66
|
+
# @param value [String, Integer, Boolean] the value of your key
|
67
|
+
#
|
68
|
+
# @example Add object "bloodbath" with value "premium"
|
69
|
+
# add_object("example", "users", "bloodbath", "premium")
|
70
|
+
#
|
71
|
+
# @deprecated Use {#create_object-class_method} instead.
|
72
|
+
def Gembase.add_object(db, category, key, value)
|
73
|
+
raise "db must be an String" until db.is_a?(String)
|
74
|
+
raise "category must be an String" until category.is_a?(String)
|
75
|
+
raise "key must be an String" until key.is_a?(String)
|
76
|
+
|
77
|
+
puts "WARNING | add_object Method is deprecated. Please use create_object Method instead."
|
78
|
+
@database
|
79
|
+
@data
|
80
|
+
@data["#{category}"].store("#{key}", "#{value}")
|
81
|
+
end
|
82
|
+
|
83
|
+
# @!method create_object(db, key, value, category=nil, subcategory=nil)
|
84
|
+
# Create an object outside a category
|
85
|
+
# @param db [String] the name of your DataBase file
|
86
|
+
# @param key [String] the key name of your object
|
87
|
+
# @param value [String, Integer, Boolean] the value of your key
|
88
|
+
# @param category [String] the name of your category
|
89
|
+
# @param subcategory [String] the name of your subcategory
|
90
|
+
#
|
91
|
+
# @example Create object "server" with value "localhost:8080". Without categories.
|
92
|
+
# create_object("example", "server", "localhost:8080")
|
93
|
+
#
|
94
|
+
# @example Create object "users-limit" with value 5 in "users" category.
|
95
|
+
# create_object("example", "users-limit", 5, "users")
|
96
|
+
#
|
97
|
+
# @example Create object "bloodbath" with value true in "premium" subcategory.
|
98
|
+
# create_object("example", "bloodbath", true, "users", "premium")
|
99
|
+
def Gembase.create_object(db, key, value, category=nil, subcategory=nil)
|
100
|
+
raise "db must be an String" until db.is_a?(String)
|
101
|
+
raise "key must be an String" until key.is_a?(String)
|
102
|
+
|
103
|
+
if category.to_s.length == 0
|
104
|
+
@database
|
105
|
+
@data
|
106
|
+
@data.store("#{key}", "#{value}")
|
107
|
+
@save
|
108
|
+
else
|
109
|
+
raise "category must be an String" until category.is_a?(String)
|
110
|
+
if subcategory.to_s.length == 0
|
111
|
+
@database
|
112
|
+
@data
|
113
|
+
@data["#{category}"].store("#{key}", "#{value}")
|
114
|
+
@save
|
115
|
+
else
|
116
|
+
raise "subcategory must be an String" until subcategory.is_a?(String)
|
117
|
+
@database
|
118
|
+
@data
|
119
|
+
@data["#{category}"]["#{subcategory}"].store("#{key}", "#{value}")
|
120
|
+
@save
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# @!method delete_object(db, key, category=nil, subcategory=nil)
|
126
|
+
# Delete an object inside/outside a category.
|
127
|
+
# @param db [String] the name of your DataBase file
|
128
|
+
# @param key [String] the key name of your object
|
129
|
+
# @param category [String] the name of your category
|
130
|
+
# @param subcategory [String] the name of your subcategory
|
131
|
+
#
|
132
|
+
# @example Deleting object inside a category
|
133
|
+
# delete_object("example", "users-limit", "users")
|
134
|
+
#
|
135
|
+
# @ example Deleting object inside a subcategory
|
136
|
+
# delete_object("example", "bloodbath", "users", "premium")
|
137
|
+
#
|
138
|
+
# @example Deleting object outside a category
|
139
|
+
# delete_object("example", "server")
|
140
|
+
#
|
141
|
+
# @note Category is an optional parameter. Use this only when you want to delete an object inside a category.
|
142
|
+
def Gembase.delete_object(db, key, category=nil, subcategory=nil)
|
143
|
+
raise "db must be an String" until db.is_a?(String)
|
144
|
+
raise "key must be an String" until key.is_a?(String)
|
145
|
+
|
146
|
+
if category.to_s.length == 0 # If there's no category argument declared.
|
147
|
+
@database
|
148
|
+
@data
|
149
|
+
@data.delete("#{key}")
|
150
|
+
File.open("#{db}.rudb", "w+") do |f|
|
151
|
+
f.write(@data.to_yaml)
|
152
|
+
end
|
153
|
+
else
|
154
|
+
if subcategory.to_s.length == 0 # If there's no subcategory argument declared.
|
155
|
+
raise "category must be an String" until category.is_a?(String)
|
156
|
+
@database
|
157
|
+
@data
|
158
|
+
@data["#{category}"].delete("#{key}")
|
159
|
+
File.open("#{db}.rudb", "w+") do |f|
|
160
|
+
f.write(@data.to_yaml)
|
161
|
+
end
|
162
|
+
else
|
163
|
+
raise "subcategory must be an String" until subcategory.is_a?(String)
|
164
|
+
@database
|
165
|
+
@data
|
166
|
+
@data["#{category}"]["#{subcategory}"].delete("#{key}")
|
167
|
+
File.open("#{db}.rudb", "w+") do |f|
|
168
|
+
f.write(@data.to_yaml)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# @!method change_object(db, key, new_value, category=nil, subcategory=nil)
|
175
|
+
# Change the value of an existing object
|
176
|
+
# @param db [String] the name of your DataBase file
|
177
|
+
# @param key [String] the key name of your object
|
178
|
+
# @param new_value [String,Integer, Boolean] the new value of your key
|
179
|
+
# @param category [String] the name of your category
|
180
|
+
# @param subcategory [String] the name of your subcategory
|
181
|
+
#
|
182
|
+
# @example Change key server value from localhost:8080 to example_host.com outside categories
|
183
|
+
# change_object("example", "server", "example_host.com")
|
184
|
+
#
|
185
|
+
# @example Change key users-limit value from 5 to 10 into users category
|
186
|
+
# change_object("example", "users-limit", "10", "users")
|
187
|
+
#
|
188
|
+
# @example Change key bloodbath value from true to false into premium subcategory
|
189
|
+
# change_object("example", "bloodbath", false, "users", "category")
|
190
|
+
#
|
191
|
+
# @since 0.5.0
|
192
|
+
def Gembase.change_object(db, key, new_value, category=nil, subcategory=nil)
|
193
|
+
raise "db must be an String" until db.is_a?(String)
|
194
|
+
raise "key must be an String" until key.is_a?(String)
|
195
|
+
|
196
|
+
if category.to_s.length == 0
|
197
|
+
@database
|
198
|
+
@data
|
199
|
+
@data["#{key}"] = new_value
|
200
|
+
@save
|
201
|
+
else
|
202
|
+
raise "category must be an String" until category.is_a?(String)
|
203
|
+
if subcategory.to_s.length == 0
|
204
|
+
@database
|
205
|
+
@data
|
206
|
+
@data["#{category}"]["#{key}"] = new_value
|
207
|
+
@save
|
208
|
+
else
|
209
|
+
raise "subcategory must be an String" until subcategory.is_a?(String)
|
210
|
+
@database
|
211
|
+
@data
|
212
|
+
@data["#{category}"]["#{subcategory}"]["#{key}"] = new_value
|
213
|
+
@save
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# @!method parse(db)
|
219
|
+
# Parse the DataBase structure to modify it
|
220
|
+
# @param db [String] the name of your DataBase file
|
221
|
+
#
|
222
|
+
# @example Parsing the DB called "example"
|
223
|
+
# parse("example")
|
224
|
+
#
|
225
|
+
# @note You can use these two methods (parse and generate) instead of YAML vanilla methods (load and to_yaml).
|
226
|
+
def Gembase.parse(db)
|
227
|
+
raise "db must be an String" until db.is_a?(String)
|
228
|
+
|
229
|
+
@database
|
230
|
+
@data
|
231
|
+
end
|
232
|
+
|
233
|
+
# @!method regenerate(db)
|
234
|
+
# Regenerate the DataBase stucture to YAML structure
|
235
|
+
# @param db [String] the name of your DataBase file
|
236
|
+
#
|
237
|
+
# @example Regenerating the DB called "example"
|
238
|
+
# regenerate("example")
|
239
|
+
def Gembase.regenerate(db)
|
240
|
+
raise "db must be an String" until db.is_a?(String)
|
241
|
+
|
242
|
+
@database
|
243
|
+
@data.to_yaml
|
244
|
+
end
|
24
245
|
end
|
metadata
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gembase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Laauuu
|
7
|
+
- NTB Bloodbath
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-02-08 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Gembase is a database gem for Ruby. Very powerful, simple and effective
|
15
14
|
based on YAML.
|
16
15
|
email:
|
17
16
|
- bloodbathalchemist@protonmail.com
|
18
|
-
- lauywe23@gmail.com
|
19
17
|
executables: []
|
20
18
|
extensions: []
|
21
19
|
extra_rdoc_files: []
|
@@ -25,7 +23,8 @@ homepage: https://rubygems.org/gems/gembase
|
|
25
23
|
licenses:
|
26
24
|
- MIT
|
27
25
|
metadata:
|
28
|
-
source_code_uri: https://github.com/
|
26
|
+
source_code_uri: https://github.com/NTBBloodbath/Gembase
|
27
|
+
documentation_uri: https://rubydoc.info/github/NTBBloodbath/Gembase/master/index
|
29
28
|
post_install_message:
|
30
29
|
rdoc_options: []
|
31
30
|
require_paths:
|
@@ -34,15 +33,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
33
|
requirements:
|
35
34
|
- - ">="
|
36
35
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
36
|
+
version: 2.6.0preview2
|
38
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
38
|
requirements:
|
40
|
-
- - "
|
39
|
+
- - ">="
|
41
40
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
41
|
+
version: '0'
|
43
42
|
requirements: []
|
44
|
-
rubygems_version: 3.0.
|
43
|
+
rubygems_version: 3.0.3
|
45
44
|
signing_key:
|
46
45
|
specification_version: 4
|
47
|
-
summary: Gembase is a database gem for Ruby.
|
46
|
+
summary: Gembase is a database gem based on YAML for Ruby.
|
48
47
|
test_files: []
|