rbdb 0.2.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c13c3bc8a03de85db353677f6ee82e23a6f68c12
4
- data.tar.gz: b16ebb27dab5f231d780ff9783026a3dbac766fe
3
+ metadata.gz: e355fb7edc3680f0d9a53b35d9f960a3b182f9d3
4
+ data.tar.gz: 3c29645b7edc11d5d187f89c552be1719c4b6d4e
5
5
  SHA512:
6
- metadata.gz: c7efb12dae8e8c1139d800253b85ce5ba56541c21db3aee6a1a46e55cd6ba1e12612843c10c0ddd3502b3f79ecdc1627c2dcf37e93fec4dfd9e12ca7f1b5a954
7
- data.tar.gz: 7c42fb1c4bcce49d7cb5025b07c189481e5b29132834e09574bba62419852490d15e154fff9f343b7c37b11162c3ecbecaab7030fed6b33f7919311dce555df8
6
+ metadata.gz: b794f599c1ce850ab55ad062c946775e507fa0c8f9d0caf1a784931d8c72d856391840e70dde7915dc819f49e0e4e26ab5a31726aeeeee695135e9f2d5ba2b64
7
+ data.tar.gz: 384ac02c507e0ab010c422516aa2f9e70d30b71517e6cdeb4d8f464d3b60590bac98bab4e29db242ddbe7756566d5ba5a8d17790750cbf28d8414f05692d3e32
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Rbdb
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rbdb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
2
+ Simple in memory database for Ruby
6
3
 
7
4
  ## Installation
8
5
 
@@ -22,18 +19,56 @@ Or install it yourself as:
22
19
 
23
20
  ## Usage
24
21
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
22
+ ```ruby
23
+ require 'rbdb'
24
+
25
+ db = Rbdb.create_db('app') # Create a DB
26
+ table = db.create_table('people') # And a table
27
+ table.fields = {name: :string, age: :integer} # Assign it a schema like field (Hash)
28
+ table.insert({name: 'John', age: 31}) # Give it some records
29
+ table.insert({name: 'Doe', age: 31})
30
+ table.find_all({age: 31})
31
+ => [{:name=>"John", :age=>31, :id=>1}, {:name=>"Doe", :age=>31, :id=>2}]
32
+ ```
33
+ Rbdb automatically assigns a unique id to each record inserted.
30
34
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+ ### Top level namespace
36
+ The top level namespace is meant to contain all databases.
37
+ ```ruby
38
+ Rbdb.create_db(name, options = {})
39
+ ```
40
+ creates a DB with name and adds it to the top level container and return it
41
+ name: The name to give to the database
42
+ options: force - If set to true, overwrites the DB with name if it exists and is not contained in the top level namespace.
43
+ ```ruby
44
+ Rbdb.add_db(db, options = {})
45
+ ```
46
+ add a DB to the top level container and return it
47
+ db: The database to add to the top level container
48
+ options: force - If set to true, overwrites the DB with db.name if it exists and is not in the top level namespace.
49
+ ```ruby
50
+ Rbdb.databases
51
+ ```
52
+ returns all databases
53
+ ```ruby
54
+ Rbdb.find_db(name)
55
+ ```
56
+ finds the database with name in the top level namespace
57
+ name: the name of the database to find.
58
+ ```ruby
59
+ Rbdb.delete_db(name)
60
+ ```
61
+ deletes the database with name in the top level namespace
62
+ name: the name of the database to delete.
63
+ ```ruby
64
+ Rbdb.flush
65
+ ```
66
+ Used for debugging and testing purposes. Deletes all DB's in the top level container.
32
67
 
33
68
  ## Contributing
34
69
 
35
- 1. Fork it ( https://github.com/[my-github-username]/rbdb/fork )
70
+ 1. Fork it ( https://github.com/dibenso/rbdb/fork )
36
71
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
72
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
73
  4. Push to the branch (`git push origin my-new-feature`)
39
- 5. Create a new Pull Request
74
+ 5. Create a new Pull Request
@@ -18,5 +18,13 @@ module Rbdb
18
18
  @tables[name] = table
19
19
  end
20
20
  end
21
+
22
+ def find_table(name)
23
+ @tables[name]
24
+ end
25
+
26
+ def [](name)
27
+ find_table(name)
28
+ end
21
29
  end
22
30
  end
@@ -5,7 +5,7 @@ module Rbdb
5
5
  ALLOWED_TYPES = [:string, :integer, :float, :boolean]
6
6
 
7
7
  attr_reader :name, :options, :fields, :records
8
-
8
+
9
9
  def initialize(name, options = {})
10
10
  @name = name
11
11
  @options = options
@@ -26,10 +26,18 @@ module Rbdb
26
26
  end
27
27
  end
28
28
 
29
- def find_by(kv_pair)
30
- return find_by_id(kv_pair.values.first) if kv_pair.keys.first.to_s == 'id'
31
- find(kv_pair) do |record|
32
- return record
29
+ def find_by(fields)
30
+ if fields.length == 1
31
+ return find_by_id(fields.values.first) if fields.keys.first.to_s == 'id'
32
+ find(fields) do |record|
33
+ return record
34
+ end
35
+ return nil
36
+ else
37
+ find_multiple_fields(fields) do |record|
38
+ return record
39
+ end
40
+ nil
33
41
  end
34
42
  end
35
43
 
@@ -37,12 +45,19 @@ module Rbdb
37
45
  return @records["#{id}"]
38
46
  end
39
47
 
40
- def find_all(kv_pair)
41
- return [find_by_id(kv_pair.values.first)] if kv_pair.keys.first == 'id'
48
+ def find_all(fields)
42
49
  found = []
43
- find(kv_pair) do |record|
44
- found << record
50
+ if fields.length == 1
51
+ return [find_by_id(fields.values.first)] if fields.keys.first == 'id'
52
+ find(fields) do |record|
53
+ found << record
54
+ end
55
+ else
56
+ find_multiple_fields(fields) do |record|
57
+ found << record
58
+ end
45
59
  end
60
+
46
61
  found
47
62
  end
48
63
 
@@ -63,9 +78,24 @@ module Rbdb
63
78
 
64
79
  private
65
80
 
66
- def find(kv_pair, &block)
81
+ def find(fields, &block)
67
82
  @records.each do |key, v|
68
- yield v if v[kv_pair.keys.first] == kv_pair.values.first
83
+ yield v if v[fields.keys.first] == fields.values.first
84
+ end
85
+ end
86
+
87
+ def find_multiple_fields(fields, &block)
88
+ @records.each do |k, v|
89
+ good = true
90
+ fields.each do |key, value|
91
+ if v[key] == value
92
+ next
93
+ else
94
+ good = false
95
+ break
96
+ end
97
+ end
98
+ yield v if good
69
99
  end
70
100
  end
71
101
 
@@ -1,3 +1,3 @@
1
1
  module Rbdb
2
- VERSION = "0.2.0"
2
+ VERSION = "0.7.0"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dibenso
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - lib/rbdb/util.rb
72
72
  - lib/rbdb/version.rb
73
73
  - rbdb-0.1.0.gem
74
+ - rbdb-0.2.0.gem
74
75
  - rbdb.gemspec
75
76
  homepage: https://github.com/dibenso/rbdb
76
77
  licenses: []