usefuldb 0.0.7 → 0.0.8
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.
- data/CHANGELOG +5 -0
- data/README +1 -1
- data/bin/usefuldb +42 -15
- data/lib/usefuldb.rb +15 -14
- data/lib/usefuldb/gui.rb +49 -32
- data/lib/usefuldb/settings.rb +21 -17
- data/lib/usefuldb/utilities.rb +21 -17
- data/lib/usefuldb/version.rb +1 -1
- data/test/main_test.rb +53 -116
- metadata +7 -7
data/CHANGELOG
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
usefuldb gem CHANGELOG
|
2
2
|
|
3
|
+
## Version 0.0.8
|
4
|
+
- Fixed issue introduced in 0.0.7 with deleting elements
|
5
|
+
- Added logging to many parts of the UsefulDB system to aid debugging, and provide support for verbose mode
|
6
|
+
- Updated main_test.rb to match the updated interface, and consolidated test methods
|
7
|
+
|
3
8
|
## Version 0.0.7
|
4
9
|
- Updated layout of the yaml database file to include description field for each entry
|
5
10
|
- Updated layout of the yaml database file to include a version field
|
data/README
CHANGED
data/bin/usefuldb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# Require statements
|
3
4
|
require 'usefuldb'
|
4
5
|
require 'optparse'
|
6
|
+
require 'logger'
|
5
7
|
|
6
8
|
#####################################################
|
7
9
|
def addColour(text, colour_code)
|
@@ -14,11 +16,20 @@ def yellow(text); addColour(text, 33); end
|
|
14
16
|
def blue(text); addColour(text, 34); end
|
15
17
|
#####################################################
|
16
18
|
|
19
|
+
# Variables
|
20
|
+
|
21
|
+
# Create the Logger instance
|
22
|
+
log = Logger.new(STDOUT)
|
23
|
+
#log.level = Logger::DEBUG
|
24
|
+
#log.level = Logger::INFO
|
25
|
+
log.level = Logger::WARN
|
26
|
+
|
27
|
+
|
17
28
|
options = {}
|
18
29
|
optparse = nil
|
19
30
|
|
20
31
|
# Setup the system for use
|
21
|
-
UsefulDB.setup
|
32
|
+
UsefulDB.setup(log)
|
22
33
|
|
23
34
|
begin
|
24
35
|
optparse = OptionParser.new do |opts|
|
@@ -31,22 +42,27 @@ UsefulDB - a simple command and URL database (#{UsefulDB::Version})
|
|
31
42
|
WELCOME
|
32
43
|
|
33
44
|
opts.on('-a', '--add', "Add an entry to the database") do |arg|
|
45
|
+
log.debug "add parameter passed"
|
34
46
|
options[:a] = arg
|
35
47
|
end
|
36
48
|
|
37
49
|
opts.on('-d', '--delete', "Delete an entry from the database") do |arg|
|
50
|
+
log.debug "delete parameter passed"
|
38
51
|
options[:d] = arg
|
39
52
|
end
|
40
53
|
|
41
54
|
opts.on('-l', '--list', "List all entries in the database") do |arg|
|
55
|
+
log.debug "list parameter passed"
|
42
56
|
options[:l] = arg
|
43
57
|
end
|
44
58
|
|
45
59
|
opts.on('-v', '--verbose', "Runs the system in verbose mode") do |arg|
|
60
|
+
log.debug "verbose parameter passed"
|
46
61
|
options[:v] = arg
|
47
62
|
end
|
48
63
|
|
49
64
|
opts.on('-h', '--help', "Print out this message") do |arg|
|
65
|
+
log.debug "help parameter passed"
|
50
66
|
puts opts
|
51
67
|
exit
|
52
68
|
end
|
@@ -54,41 +70,52 @@ WELCOME
|
|
54
70
|
end.parse!
|
55
71
|
rescue OptionParser::InvalidOption => e
|
56
72
|
puts e.message + "\n\nUseage: usefuldb -h or --help for help using the system"
|
73
|
+
log.fatal e.message
|
57
74
|
exit()
|
58
75
|
end
|
59
76
|
|
60
77
|
#############################################################################
|
61
78
|
|
62
79
|
# Checking for flag parameters
|
80
|
+
log.debug "Checking for parameters"
|
63
81
|
if options.empty?
|
64
|
-
|
82
|
+
log.debug "No flag parameters were passed"
|
83
|
+
log.debug "Checking if ARGV is empty"
|
65
84
|
if ARGV.empty?
|
85
|
+
log.debug "No parameters of any kind were passed, exiting"
|
66
86
|
puts "Useage: usefuldb -h or --help for help using the system"
|
67
87
|
exit()
|
68
|
-
|
69
|
-
# At least one non flag parameter was passed
|
70
88
|
else
|
71
|
-
|
72
|
-
|
89
|
+
log.debug "At least one non flag parameter was passed, launching the search system"
|
90
|
+
log.debug ARGV
|
91
|
+
puts "Launching the search system:"
|
92
|
+
UsefulDB::GUI.search(ARGV, log)
|
73
93
|
end
|
74
94
|
|
75
|
-
# Some flags parameters were passed
|
76
95
|
else
|
77
|
-
|
96
|
+
log.debug "Some flags parameters were passed"
|
97
|
+
log.debug options
|
78
98
|
|
79
|
-
if options[:
|
80
|
-
|
81
|
-
|
99
|
+
if options[:v]
|
100
|
+
log.level = Logger::INFO
|
101
|
+
end
|
102
|
+
|
103
|
+
if options[:a]
|
104
|
+
log.debug "The -a or --add flag is true, launching add system"
|
105
|
+
puts "Launching the add system:"
|
106
|
+
UsefulDB::GUI.add(log)
|
82
107
|
|
83
108
|
elsif options[:l]
|
109
|
+
log.debug "The -l or --list flag is true, launching the list system"
|
84
110
|
puts green("Launching the list system:")
|
85
|
-
UsefulDB::GUI.list
|
111
|
+
UsefulDB::GUI.list(log)
|
86
112
|
|
87
|
-
elsif options[:d]
|
113
|
+
elsif options[:d]
|
114
|
+
log.debug "The -d or --delete flag is true, launching the delete system"
|
88
115
|
puts "Run the delete system:"
|
89
|
-
UsefulDB::GUI.remove(
|
90
|
-
|
116
|
+
UsefulDB::GUI.remove(log)
|
91
117
|
end
|
118
|
+
|
92
119
|
end
|
93
120
|
|
94
121
|
|
data/lib/usefuldb.rb
CHANGED
@@ -4,36 +4,37 @@ require 'usefuldb/exceptions'
|
|
4
4
|
require 'usefuldb/gui'
|
5
5
|
require 'usefuldb/version'
|
6
6
|
require 'fileutils'
|
7
|
+
require 'logger'
|
7
8
|
|
8
9
|
module UsefulDB
|
9
10
|
class << self
|
10
11
|
|
11
|
-
def add(hash,
|
12
|
-
UsefulDB::UsefulUtils.add(hash,
|
12
|
+
def add(hash, log)
|
13
|
+
UsefulDB::UsefulUtils.add(hash, log)
|
13
14
|
end
|
14
15
|
|
15
|
-
def count()
|
16
|
-
UsefulDB::UsefulUtils.count
|
16
|
+
def count(log)
|
17
|
+
UsefulDB::UsefulUtils.count(log)
|
17
18
|
end
|
18
19
|
|
19
|
-
def remove(key,
|
20
|
-
UsefulDB::UsefulUtils.remove(key,
|
20
|
+
def remove(key, log)
|
21
|
+
UsefulDB::UsefulUtils.remove(key, log)
|
21
22
|
end
|
22
23
|
|
23
|
-
def dbSave
|
24
|
-
UsefulDB::UsefulUtils.dbSave
|
24
|
+
def dbSave(log)
|
25
|
+
UsefulDB::UsefulUtils.dbSave(log)
|
25
26
|
end
|
26
27
|
|
27
|
-
def dbLoad
|
28
|
-
UsefulDB::UsefulUtils.dbLoad
|
28
|
+
def dbLoad(log)
|
29
|
+
UsefulDB::UsefulUtils.dbLoad(log)
|
29
30
|
end
|
30
31
|
|
31
|
-
def search(args)
|
32
|
-
return UsefulDB::UsefulUtils.search(args)
|
32
|
+
def search(args, log)
|
33
|
+
return UsefulDB::UsefulUtils.search(args, log)
|
33
34
|
end
|
34
35
|
|
35
|
-
def setup
|
36
|
-
UsefulDB::UsefulUtils.setup
|
36
|
+
def setup(log)
|
37
|
+
UsefulDB::UsefulUtils.setup(log)
|
37
38
|
end
|
38
39
|
|
39
40
|
end
|
data/lib/usefuldb/gui.rb
CHANGED
@@ -5,16 +5,28 @@ module UsefulDB
|
|
5
5
|
class GUI
|
6
6
|
class << self
|
7
7
|
attr_accessor
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
|
9
|
+
|
10
|
+
# Search the database
|
11
|
+
def search(args, log)
|
12
|
+
log.debug "Loading the database"
|
13
|
+
UsefulDB.dbLoad(log)
|
14
|
+
|
15
|
+
log.debug "Launching UsefulDB::UsefulUtils.search"
|
16
|
+
args.each {|i| puts "\n" + UsefulDB::UsefulUtils.search(i, log)}
|
12
17
|
end
|
13
18
|
|
14
|
-
|
15
|
-
|
19
|
+
|
20
|
+
# List entries in the database
|
21
|
+
def list(log)
|
22
|
+
log.debug "Loading the database"
|
23
|
+
UsefulDB.dbLoad(log)
|
24
|
+
|
25
|
+
log.debug "Launching UsefulDB::UsefulUtils.list"
|
16
26
|
index = 0
|
17
|
-
UsefulDB::UsefulUtils.list
|
27
|
+
listing = UsefulDB::UsefulUtils.list(log)
|
28
|
+
|
29
|
+
listing.each do |i|
|
18
30
|
puts "Element: " + index.to_s
|
19
31
|
index += 1
|
20
32
|
msg = ''
|
@@ -23,62 +35,67 @@ module UsefulDB
|
|
23
35
|
puts "- Value: " + i["value"]
|
24
36
|
puts "- Description: " + i["description"] + "\n\n##\n"
|
25
37
|
end
|
38
|
+
|
39
|
+
log.info "Number of entries in the database is: " + UsefulDB::UsefulUtils.count(log).to_s
|
26
40
|
end
|
27
41
|
|
28
42
|
|
29
|
-
|
30
|
-
def remove(
|
31
|
-
|
32
|
-
list()
|
43
|
+
# Remove an entry from the database
|
44
|
+
def remove(log)
|
45
|
+
log.info "Printing out the list of database entries\n"
|
46
|
+
list(log)
|
33
47
|
|
34
48
|
puts "Enter the number of the element from the list above which you want to delete"
|
35
49
|
value = STDIN.gets
|
50
|
+
log.debug value
|
36
51
|
|
37
52
|
begin
|
38
|
-
UsefulDB.remove(value.to_i,
|
39
|
-
|
53
|
+
UsefulDB.remove(value.to_i, log)
|
54
|
+
log.info "Entry removed"
|
55
|
+
UsefulDB.dbSave(log)
|
56
|
+
log.info "Saving database"
|
40
57
|
rescue KeyOutOfBounds => e
|
41
58
|
puts e.message + "\nexiting."
|
59
|
+
log.fatal e.message
|
42
60
|
exit()
|
43
61
|
end
|
44
62
|
|
45
63
|
end
|
46
64
|
|
47
|
-
|
48
|
-
|
49
|
-
|
65
|
+
|
66
|
+
# Add element to the database
|
67
|
+
def add(log)
|
68
|
+
UsefulDB.dbLoad(log)
|
50
69
|
|
51
|
-
|
52
|
-
|
53
|
-
puts "Please enter the comma separated search tags like the following:"
|
54
|
-
puts "eg:\nterm1, term2, term3\n\n"
|
55
|
-
else
|
56
|
-
puts "Please enter the comma separated search tags like the following:"
|
57
|
-
end
|
70
|
+
puts "Please enter the comma separated search tags like the following:"
|
71
|
+
log.info "eg:\nterm1, term2, term3\n\n"
|
58
72
|
|
59
73
|
begin
|
60
74
|
tags = ((STDIN.gets).strip).split(', ')
|
61
|
-
|
75
|
+
log.debug tags.inspect
|
76
|
+
|
62
77
|
puts "Please enter the value you wish to store for this database entry:"
|
63
78
|
value = (STDIN.gets).strip
|
79
|
+
log.debug value
|
64
80
|
|
65
81
|
puts "Please enter a description for this entry: "
|
66
82
|
description = (STDIN.gets).strip
|
83
|
+
log.debug description
|
67
84
|
|
68
85
|
entry = {"tag" => tags, "value" => value, "description" => description}
|
69
86
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
puts "Description: " + description
|
75
|
-
end
|
87
|
+
log.info "Storing the following in the database:"
|
88
|
+
log.info "Search tags: " + UsefulDB::UsefulUtils.array_to_s(tags)
|
89
|
+
log.info "Entry Value: " + value
|
90
|
+
log.info "Description: " + description
|
76
91
|
|
77
|
-
UsefulDB.add(entry,
|
78
|
-
UsefulDB.dbSave
|
92
|
+
UsefulDB.add(entry, log)
|
93
|
+
UsefulDB.dbSave(log)
|
94
|
+
log.info "Saving database"
|
79
95
|
|
80
96
|
rescue Exception => e
|
81
97
|
puts e.message
|
98
|
+
log.fatal e.message
|
82
99
|
exit
|
83
100
|
end
|
84
101
|
|
data/lib/usefuldb/settings.rb
CHANGED
@@ -5,28 +5,32 @@ module UsefulDB
|
|
5
5
|
class Settings
|
6
6
|
class << self
|
7
7
|
|
8
|
-
attr_accessor :data
|
8
|
+
attr_accessor :data;
|
9
9
|
|
10
10
|
# Loads the database from disk
|
11
|
-
def load(path)
|
11
|
+
def load(path, log)
|
12
12
|
begin
|
13
13
|
@data = YAML.load(File.open(path))
|
14
14
|
|
15
15
|
if @data.class == Array
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
log.warn "Assuming currently installed DB version < 0.0.7 running autoConvert"
|
17
|
+
|
18
|
+
autoConvert(log)
|
19
|
+
log.warn "Database conversion successful"
|
20
|
+
save(@data, path, log)
|
21
|
+
log.debug "Saving the database"
|
19
22
|
elsif @data["version"] != UsefulDB::Version.to_s
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
log.warn "The database version is lower than the latest version running autoUpgrade"
|
24
|
+
|
25
|
+
autoUpgrade(log)
|
26
|
+
log.warn "Database upgrade successful"
|
27
|
+
save(@data, path, log)
|
28
|
+
log.debug "Saving the database"
|
23
29
|
else
|
24
|
-
|
30
|
+
log.debug "Database version is current"
|
25
31
|
end
|
26
32
|
|
27
|
-
|
28
|
-
# Debug
|
29
|
-
#puts @data.inspect
|
33
|
+
log.debug @data.inspect
|
30
34
|
|
31
35
|
rescue ArgumentError => e
|
32
36
|
exit("Could not parse YAML: #{e.message}")
|
@@ -35,7 +39,7 @@ module UsefulDB
|
|
35
39
|
|
36
40
|
|
37
41
|
# Saves the database to disk
|
38
|
-
def save(newData, path)
|
42
|
+
def save(newData, path, log)
|
39
43
|
@data = newData
|
40
44
|
f = File.open(path, "w")
|
41
45
|
f.write(@data.to_yaml)
|
@@ -44,8 +48,8 @@ module UsefulDB
|
|
44
48
|
|
45
49
|
|
46
50
|
# Converts from db versions < 0.0.6 to the structure introduced in version 0.0.7
|
47
|
-
def autoConvert()
|
48
|
-
|
51
|
+
def autoConvert(log)
|
52
|
+
log.warn "autoConvert Method executing"
|
49
53
|
convertedDB = {"version" => UsefulDB::Version.to_s, "db" => @data}
|
50
54
|
|
51
55
|
convertedDB["db"].each do |element|
|
@@ -57,8 +61,8 @@ module UsefulDB
|
|
57
61
|
|
58
62
|
|
59
63
|
# Convert the db from versions lower than the latest version of usefuldb to the latest version
|
60
|
-
def autoUpgrade()
|
61
|
-
|
64
|
+
def autoUpgrade(log)
|
65
|
+
log.warn "autoUpgrade Method executing"
|
62
66
|
@data["version"] = UsefulDB::Version.to_s
|
63
67
|
end
|
64
68
|
|
data/lib/usefuldb/utilities.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'usefuldb/exceptions'
|
2
|
+
require 'logger'
|
2
3
|
|
3
4
|
module UsefulDB
|
4
5
|
|
@@ -20,28 +21,28 @@ module UsefulDB
|
|
20
21
|
|
21
22
|
|
22
23
|
# Save the database to disk
|
23
|
-
def dbSave()
|
24
|
+
def dbSave(log)
|
24
25
|
if @dbpath.nil?
|
25
|
-
|
26
|
+
log.debug @dbpath = File.expand_path(File.dirname(__FILE__) + '/../../resources/db.yaml')
|
26
27
|
@dbpath = ENV['HOME'] + "/.usefuldb/db.yaml"
|
27
|
-
Settings.save(@data, @dbpath)
|
28
|
+
UsefulDB::Settings.save(@data, @dbpath, log)
|
28
29
|
else
|
29
|
-
Settings.save(@data, @dbpath)
|
30
|
+
UsefulDB::Settings.save(@data, @dbpath, log)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
|
34
35
|
# Load the database from disk
|
35
|
-
def dbLoad()
|
36
|
-
|
36
|
+
def dbLoad(log)
|
37
|
+
log.debug @dbpath = File.expand_path(File.dirname(__FILE__) + '/../../resources/db.yaml')
|
37
38
|
@dbpath = ENV['HOME'] + "/.usefuldb/db.yaml"
|
38
|
-
Settings.load(dbpath)
|
39
|
-
@data = Settings.data
|
39
|
+
UsefulDB::Settings.load(@dbpath, log)
|
40
|
+
@data = UsefulDB::Settings.data
|
40
41
|
end
|
41
42
|
|
42
43
|
|
43
44
|
# Return the number of elements in the database.
|
44
|
-
def count()
|
45
|
+
def count(log)
|
45
46
|
if @data["db"].count == 0
|
46
47
|
raise EmptyDB, "The DB is currently empty."
|
47
48
|
else
|
@@ -51,39 +52,42 @@ module UsefulDB
|
|
51
52
|
|
52
53
|
|
53
54
|
# Add an element to the database
|
54
|
-
def add(hash,
|
55
|
+
def add(hash, log)
|
55
56
|
if @data["db"].include?(hash) then raise EntryInDB, "Entry already in the DB"; else @data["db"] << hash; end
|
56
57
|
end
|
57
58
|
|
58
59
|
|
59
60
|
# Remove an element from the database
|
60
|
-
def remove(key,
|
61
|
+
def remove(key, log)
|
61
62
|
if @data["db"].count == 0
|
62
63
|
raise EmptyDB, "You cannot call the remove function on an empty Database!"
|
63
64
|
elsif @data["db"].count <= key || key < 0
|
64
65
|
raise KeyOutOfBounds, "Key is out of bounds and therefore does not exist in the DB"
|
65
66
|
else
|
66
|
-
@data.delete_at(key)
|
67
|
+
@data["db"].delete_at(key)
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
71
|
|
71
72
|
# Setup the system for the first time
|
72
|
-
def setup()
|
73
|
+
def setup(log)
|
74
|
+
log.debug "Checking to see if the database is already installed"
|
73
75
|
resourceDir = ENV['HOME'] + "/.usefuldb/"
|
76
|
+
log.debug resourceDir
|
74
77
|
if File.directory?(resourceDir)
|
75
|
-
|
78
|
+
log.debug "The folder already exists, do nothing"
|
76
79
|
else
|
77
|
-
|
80
|
+
log.debug "Creating ~/.usefuldb/ and installing the DB there."
|
78
81
|
FileUtils.mkdir(resourceDir)
|
79
82
|
dbpath = File.expand_path(File.dirname(__FILE__) + '/../../resources/db.yaml')
|
80
83
|
FileUtils.cp(dbpath, resourceDir)
|
84
|
+
log.debug "Database copied to ~/.usefuldb/db.yaml"
|
81
85
|
end
|
82
86
|
end
|
83
87
|
|
84
88
|
|
85
89
|
# Search for a tag in the DB
|
86
|
-
def search(tag)
|
90
|
+
def search(tag, log)
|
87
91
|
msg = "Searching the database for tag: " + tag + "\n"
|
88
92
|
|
89
93
|
@data["db"].each do |db|
|
@@ -98,7 +102,7 @@ module UsefulDB
|
|
98
102
|
|
99
103
|
|
100
104
|
# List out all elements in the DB
|
101
|
-
def list
|
105
|
+
def list(log)
|
102
106
|
return @data["db"]
|
103
107
|
end
|
104
108
|
|
data/lib/usefuldb/version.rb
CHANGED
data/test/main_test.rb
CHANGED
@@ -2,9 +2,12 @@ require 'test/unit'
|
|
2
2
|
require 'rack/test'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'usefuldb'
|
5
|
+
require 'logger'
|
5
6
|
|
6
7
|
ENV['RACK_ENV'] = 'test'
|
7
8
|
|
9
|
+
log = nil
|
10
|
+
|
8
11
|
#####################################################
|
9
12
|
def addColour(text, colour_code)
|
10
13
|
"\e[#{colour_code}m#{text}\e[0m"
|
@@ -17,149 +20,83 @@ def blue(text); addColour(text, 34); end
|
|
17
20
|
#####################################################
|
18
21
|
|
19
22
|
|
23
|
+
|
24
|
+
|
20
25
|
class UsefulDBTest < Test::Unit::TestCase
|
21
26
|
|
22
27
|
include Rack::Test::Methods
|
23
28
|
|
29
|
+
attr_accessor :log
|
30
|
+
|
24
31
|
def setup
|
25
|
-
|
32
|
+
|
33
|
+
if @log == nil
|
34
|
+
@log = log = Logger.new(STDOUT)
|
35
|
+
@log.level = Logger::INFO
|
36
|
+
end
|
37
|
+
|
38
|
+
UsefulDB::dbLoad(@log)
|
26
39
|
end
|
27
40
|
|
28
|
-
|
29
|
-
|
30
|
-
|
41
|
+
def teardown
|
42
|
+
# Do nothing
|
43
|
+
end
|
31
44
|
|
32
45
|
|
33
46
|
# Test to check adding of entries to the database
|
34
47
|
def test_add
|
35
|
-
|
48
|
+
@log.info "Executing test: test_add"
|
49
|
+
|
50
|
+
startingCount = UsefulDB.count(@log)
|
51
|
+
@log.info "The number of starting database entries: " + startingCount.to_s
|
36
52
|
|
37
53
|
begin
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
UsefulDB.
|
54
|
+
@log.info "Test to check adding an element to the database succeeds"
|
55
|
+
entry1 = {"tag" => ["testing", "the", "database", "dbtest"], "value" => "dbtest", "description" => "dbtest"}
|
56
|
+
@log.info "Create a new entry:" + entry1.inspect
|
57
|
+
UsefulDB.add(entry1, @log)
|
58
|
+
@log.info "Adding element to the database"
|
59
|
+
|
60
|
+
@log.info "Check the total number of entries in the DB was increased by one " +
|
61
|
+
assert_equal(startingCount + 1, UsefulDB.count(@log)).to_s
|
62
|
+
|
63
|
+
@log.info "Test to check adding duplicate element to the DB fails"
|
64
|
+
entry2 = {"tag" => ["install", "rubygems", "website", "usefuldb"], "value" => "http://rubygems.org/usefuldb", "description" => "Website URL for the usefuldb gem"}
|
65
|
+
@log.info "Create a new entry: " + entry2.inspect
|
66
|
+
UsefulDB.add(entry2, @log)
|
46
67
|
|
47
68
|
rescue UsefulDB::EmptyDB => e
|
48
69
|
assert(false, red(e.message))
|
49
70
|
rescue UsefulDB::EntryInDB => e
|
50
|
-
|
51
|
-
#puts e.backtrace
|
71
|
+
@log.info e.message + " this is expected"
|
52
72
|
end
|
53
73
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
UsefulDB.dbLoad
|
58
|
-
|
59
|
-
puts "Check the total number of entries in the DB is still 2 " +
|
60
|
-
blue(assert_equal(2, UsefulDB.count).to_s)
|
61
|
-
rescue UsefulDB::EmptyDB => e
|
62
|
-
assert(false, red(e.message))
|
63
|
-
end
|
74
|
+
tempCount = startingCount + 1
|
75
|
+
@log.info "Check the total number of entries in the DB is still #{tempCount} " +
|
76
|
+
assert_equal(startingCount + 1, UsefulDB.count(@log)).to_s
|
64
77
|
|
65
|
-
msg = "Test to check adding new element to the DB succeeds: "
|
66
78
|
begin
|
67
|
-
|
68
|
-
|
79
|
+
@log.info "Write the DB structure back to disk and then reload"
|
80
|
+
UsefulDB.dbSave(@log)
|
81
|
+
UsefulDB.dbLoad(@log)
|
69
82
|
|
70
|
-
|
71
|
-
|
83
|
+
@log.info "Check the total number of entries in the DB is still #{tempCount} " +
|
84
|
+
assert_equal(startingCount + 1, UsefulDB.count(@log)).to_s
|
72
85
|
|
73
|
-
|
74
|
-
|
75
|
-
#puts e.backtrace
|
76
|
-
rescue UsefulDB::EmptyDB => e
|
77
|
-
assert(false, red(e.message))
|
78
|
-
end
|
79
|
-
|
80
|
-
puts green("test_add passed")
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
# Test to check saving entries to the database
|
85
|
-
def test_save
|
86
|
-
puts yellow("\n## Executing test_save")
|
87
|
-
|
88
|
-
msg = "Test to check adding new element to the DB succeeds: "
|
89
|
-
begin
|
90
|
-
entry = {"tag" => ["interesting", "gem", "website", "twitter"], "value" => "https://github.com/sferik/twitter/"}
|
91
|
-
puts "Creating another element" + entry.inspect
|
86
|
+
@log.info "Deleting this test entry from the database"
|
87
|
+
UsefulDB::remove(startingCount, @log)
|
92
88
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
puts red(e.message) + green(" this is expected")
|
97
|
-
#puts e.backtrace
|
98
|
-
rescue UsefulDB::EmptyDB => e
|
99
|
-
assert(false, red(e.message))
|
100
|
-
end
|
101
|
-
|
102
|
-
begin
|
103
|
-
puts "Saving the DB"
|
104
|
-
UsefulDB.dbSave
|
105
|
-
UsefulDB.dbLoad
|
106
|
-
|
107
|
-
puts "Check the total number of entries in the DB is now 3 " +
|
108
|
-
blue(assert_equal(3, UsefulDB.count).to_s)
|
109
|
-
rescue UsefulDB::EmptyDB => e
|
110
|
-
assert(false, red(e.message))
|
111
|
-
end
|
112
|
-
|
113
|
-
begin
|
114
|
-
UsefulDB.remove(2, {})
|
115
|
-
UsefulDB.dbSave
|
116
|
-
rescue UsefulDB::KeyOutOfBounds => e
|
117
|
-
assert(false, red(e.message))
|
118
|
-
rescue UsefulDB::EmptyDB => e
|
119
|
-
assert(false, red(e.message))
|
120
|
-
end
|
121
|
-
|
122
|
-
puts green("test_save passed")
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
# Test to check removal of entries from the database
|
127
|
-
def test_remove()
|
128
|
-
puts yellow("\n## Executing test_remove")
|
129
|
-
|
130
|
-
begin
|
131
|
-
puts "Test to check adding new element to the DB succeeds"
|
89
|
+
@log.info "Write the DB structure back to disk and then reload"
|
90
|
+
UsefulDB.dbSave(@log)
|
91
|
+
UsefulDB.dbLoad(@log)
|
132
92
|
|
133
|
-
|
134
|
-
|
135
|
-
puts "Creating another element" + entry.inspect + " and " + entry2.inspect
|
136
|
-
|
137
|
-
UsefulDB.add(entry, {})
|
138
|
-
UsefulDB.add(entry2, {})
|
139
|
-
rescue UsefulDB::EntryInDB => e
|
140
|
-
assert(false, red(e.message))
|
141
|
-
end
|
142
|
-
|
143
|
-
begin
|
144
|
-
puts "Saving the DB"
|
145
|
-
UsefulDB.dbSave
|
146
|
-
UsefulDB.dbLoad
|
147
|
-
|
148
|
-
puts "Removing those 2 entries from the database"
|
149
|
-
UsefulDB.remove(2, {})
|
150
|
-
puts blue(assert_equal(3, UsefulDB.count))
|
151
|
-
UsefulDB.remove(2, {})
|
152
|
-
puts blue(assert_equal(2, UsefulDB.count))
|
153
|
-
|
154
|
-
puts "Saving the DB"
|
155
|
-
UsefulDB.dbSave
|
156
|
-
rescue UsefulDB::KeyOutOfBounds => e
|
157
|
-
assert(false, red(e.message))
|
93
|
+
@log.info "Check the total number of entries in the DB is back to #{startingCount} " +
|
94
|
+
assert_equal(startingCount, UsefulDB.count(@log)).to_s
|
158
95
|
rescue UsefulDB::EmptyDB => e
|
159
96
|
assert(false, red(e.message))
|
160
|
-
end
|
161
|
-
|
162
|
-
|
97
|
+
end
|
98
|
+
|
99
|
+
@log.info "test_add passed"
|
163
100
|
end
|
164
101
|
|
165
102
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usefuldb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -68,17 +68,17 @@ executables:
|
|
68
68
|
extensions: []
|
69
69
|
extra_rdoc_files: []
|
70
70
|
files:
|
71
|
-
- lib/usefuldb
|
72
|
-
- lib/usefuldb/settings.rb
|
71
|
+
- lib/usefuldb.rb
|
73
72
|
- lib/usefuldb/version.rb
|
74
73
|
- lib/usefuldb/gui.rb
|
74
|
+
- lib/usefuldb/utilities.rb
|
75
75
|
- lib/usefuldb/exceptions.rb
|
76
|
-
- lib/usefuldb.rb
|
76
|
+
- lib/usefuldb/settings.rb
|
77
77
|
- bin/usefuldb
|
78
|
-
- README
|
79
78
|
- COPYING
|
80
79
|
- CHANGELOG
|
81
80
|
- Rakefile
|
81
|
+
- README
|
82
82
|
- resources/db.yaml
|
83
83
|
- test/main_test.rb
|
84
84
|
homepage: http://rubygems.org/gems/usefuldb
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.23
|
108
108
|
signing_key:
|
109
109
|
specification_version: 3
|
110
110
|
summary: A simple commands and URLs database for storage of useful information
|