usefuldb 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  usefuldb gem CHANGELOG
2
2
 
3
+ ## Version 0.0.7
4
+ - Updated layout of the yaml database file to include description field for each entry
5
+ - Updated layout of the yaml database file to include a version field
6
+ - Updated system to allow automatic upgrading of older databases to the new structure
7
+
3
8
  ## Version 0.0.6
4
9
  - Added UsefulDB::UsefulUtils.array_to_s to convert an array into a string identical to Ruby 1.9.1 +'s Array#to_s
5
10
  - Removed colour output so as to display correctly on Windows hosts through JRuby
data/README CHANGED
@@ -1,4 +1,4 @@
1
- ## Readme - v0.0.5
1
+ ## Readme - v0.0.6
2
2
 
3
3
  ### Install
4
4
  To run the unit tests use the following rake target
data/lib/usefuldb/gui.rb CHANGED
@@ -20,7 +20,8 @@ module UsefulDB
20
20
  msg = ''
21
21
  msg += "- Tags: " + UsefulDB::UsefulUtils.array_to_s(i["tag"]) + "\n"
22
22
  puts msg
23
- puts "- Value: " + i["value"] + "\n\n##\n"
23
+ puts "- Value: " + i["value"]
24
+ puts "- Description: " + i["description"] + "\n\n##\n"
24
25
  end
25
26
  end
26
27
 
@@ -46,40 +47,35 @@ module UsefulDB
46
47
 
47
48
  def add(opts)
48
49
  UsefulDB.dbLoad
49
- if opts[:v] then puts "in verbose mode\n"; end
50
50
 
51
- puts "Please enter the comma separated search tags like the following:"
52
- if opts[:v] then puts "eg:\nterm1, term2, term3\n\n"; end
51
+ if opts[:v]
52
+ puts "in verbose mode\n"
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
53
58
 
54
59
  begin
55
60
  tags = ((STDIN.gets).strip).split(', ')
56
- puts "The following was captured: " + UsefulDB::UsefulUtils.array_to_s(tags)
57
- puts "Is this correct? y/n"
61
+
62
+ puts "Please enter the value you wish to store for this database entry:"
63
+ value = (STDIN.gets).strip
58
64
 
59
- input = (STDIN.gets).strip
60
- if input == "y"
61
- puts "Please enter the value you wish to store for this database entry:"
62
- value = (STDIN.gets).strip
63
-
64
- puts "The following was captured: " + value
65
- puts "Is this correct? y/n"
66
- input = (STDIN.gets).strip
67
- if input == "y"
68
- entry = {"tag" => tags, "value" => value}
69
-
70
- if opts[:v] then puts "Storing the following in the database:\n" + entry.to_s; end
71
-
72
- UsefulDB.add(entry, {})
73
- UsefulDB.dbSave
74
-
75
- else
76
- puts "Exiting"
77
- exit
78
- end
79
- else
80
- puts "Exiting"
81
- exit
65
+ puts "Please enter a description for this entry: "
66
+ description = (STDIN.gets).strip
67
+
68
+ entry = {"tag" => tags, "value" => value, "description" => description}
69
+
70
+ if opts[:v]
71
+ puts "Storing the following in the database:\n"
72
+ puts "Search tags: " + UsefulDB::UsefulUtils.array_to_s(tags)
73
+ puts "Entry Value: " + value
74
+ puts "Description: " + description
82
75
  end
76
+
77
+ UsefulDB.add(entry, {})
78
+ UsefulDB.dbSave
83
79
 
84
80
  rescue Exception => e
85
81
  puts e.message
@@ -7,21 +7,61 @@ module UsefulDB
7
7
 
8
8
  attr_accessor :data
9
9
 
10
+ # Loads the database from disk
10
11
  def load(path)
11
- @data = begin
12
- YAML.load(File.open(path))
12
+ begin
13
+ @data = YAML.load(File.open(path))
14
+
15
+ if @data.class == Array
16
+ puts "Assuming currently installed DB version < 0.0.7 running autoConvert"
17
+ autoConvert()
18
+ save(@data, path)
19
+ elsif @data["version"] != UsefulDB::Version.to_s
20
+ puts "The database version is lower than the latest version running autoUpgrade"
21
+ autoUpgrade()
22
+ save(@data, path)
23
+ else
24
+ #puts "Database version is current"
25
+ end
26
+
27
+
28
+ # Debug
29
+ #puts @data.inspect
30
+
13
31
  rescue ArgumentError => e
14
32
  exit("Could not parse YAML: #{e.message}")
15
33
  end
16
34
  end
17
35
 
36
+
37
+ # Saves the database to disk
18
38
  def save(newData, path)
19
39
  @data = newData
20
40
  f = File.open(path, "w")
21
41
  f.write(@data.to_yaml)
22
42
  f.close
23
43
  end
24
-
44
+
45
+
46
+ # Converts from db versions < 0.0.6 to the structure introduced in version 0.0.7
47
+ def autoConvert()
48
+ puts "autoConvert Method executing"
49
+ convertedDB = {"version" => UsefulDB::Version.to_s, "db" => @data}
50
+
51
+ convertedDB["db"].each do |element|
52
+ element["description"] = "nil"
53
+ end
54
+
55
+ @data = convertedDB
56
+ end
57
+
58
+
59
+ # Convert the db from versions lower than the latest version of usefuldb to the latest version
60
+ def autoUpgrade()
61
+ puts "autoUpgrade Method executing"
62
+ @data["version"] = UsefulDB::Version.to_s
63
+ end
64
+
25
65
  end
26
66
  end
27
67
 
@@ -42,25 +42,25 @@ module UsefulDB
42
42
 
43
43
  # Return the number of elements in the database.
44
44
  def count()
45
- if @data.count == 0
45
+ if @data["db"].count == 0
46
46
  raise EmptyDB, "The DB is currently empty."
47
47
  else
48
- return @data.count
48
+ return @data["db"].count
49
49
  end
50
50
  end
51
51
 
52
52
 
53
53
  # Add an element to the database
54
54
  def add(hash, opts)
55
- if @data.include?(hash) then raise EntryInDB, "Entry already in the DB"; else @data << hash; end
55
+ if @data["db"].include?(hash) then raise EntryInDB, "Entry already in the DB"; else @data["db"] << hash; end
56
56
  end
57
57
 
58
58
 
59
59
  # Remove an element from the database
60
60
  def remove(key, opts)
61
- if @data.count == 0
61
+ if @data["db"].count == 0
62
62
  raise EmptyDB, "You cannot call the remove function on an empty Database!"
63
- elsif @data.count <= key || key < 0
63
+ elsif @data["db"].count <= key || key < 0
64
64
  raise KeyOutOfBounds, "Key is out of bounds and therefore does not exist in the DB"
65
65
  else
66
66
  @data.delete_at(key)
@@ -86,10 +86,11 @@ module UsefulDB
86
86
  def search(tag)
87
87
  msg = "Searching the database for tag: " + tag + "\n"
88
88
 
89
- @data.each do |db|
89
+ @data["db"].each do |db|
90
90
  if db["tag"].include?(tag)
91
91
  msg += "- Tags: " + array_to_s(db["tag"]) + "\n"
92
- msg += "- Value: " + db["value"] + "\n##\n"
92
+ msg += "- Value: " + db["value"] + "\n"
93
+ msg += "- Description: " + db["description"] +"\n##\n"
93
94
  end
94
95
  end
95
96
  return msg
@@ -98,7 +99,7 @@ module UsefulDB
98
99
 
99
100
  # List out all elements in the DB
100
101
  def list
101
- return @data
102
+ return @data["db"]
102
103
  end
103
104
 
104
105
 
@@ -7,7 +7,7 @@ module UsefulDB
7
7
 
8
8
  MAJOR = 0 unless defined? MAJOR
9
9
  MINOR = 0 unless defined? MINOR
10
- PATCH = 6 unless defined? PATCH
10
+ PATCH = 7 unless defined? PATCH
11
11
 
12
12
  def to_s
13
13
  [MAJOR, MINOR, PATCH].compact.join('.')
data/resources/db.yaml CHANGED
@@ -1,13 +1,42 @@
1
1
  ---
2
- - tag:
3
- - install
4
- - rubygems
5
- - website
6
- - usefuldb
7
- value: http://rubygems.org/usefuldb
8
- - tag:
9
- - search
10
- - find
11
- - website
12
- - google
13
- value: http://www.google.com
2
+ version: 0.0.7
3
+ db:
4
+ - tag:
5
+ - install
6
+ - rubygems
7
+ - website
8
+ - usefuldb
9
+ value: http://rubygems.org/usefuldb
10
+ description: Website URL for the usefuldb gem
11
+ - tag:
12
+ - search
13
+ - find
14
+ - website
15
+ - google
16
+ value: http://www.google.com
17
+ description: Google a major search engine
18
+ - tag:
19
+ - git
20
+ - add
21
+ value: git add <path>
22
+ description: Requesting git add files to the current git branch
23
+ - tag:
24
+ - git
25
+ - commit
26
+ value: git commit -m 'commit message'
27
+ description: Committing the files along with a commit message to the current git branch
28
+ - tag:
29
+ - git
30
+ - push
31
+ value: git push origin <branch>
32
+ description: Requesting git upload the commited changes to the remote branch
33
+ - tag:
34
+ - git
35
+ - merge
36
+ value: git merge --no-ff <branch>
37
+ description: Command to merge the specified branch into the current branch
38
+ - tag:
39
+ - git
40
+ - checkout
41
+ value: git checkout <branch>
42
+ description: Checkout the specified branch
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: