gkv 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CODE_OF_CONDUCT.md +1 -0
- data/README.md +28 -4
- data/bench.rb +13 -0
- data/example/README.md +29 -0
- data/example/server.rb +28 -0
- data/lib/gkv/database.rb +8 -0
- data/lib/gkv/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 174cf3ce2358008f146a194a0ce22e77e81b2064
|
4
|
+
data.tar.gz: b0ed3ba9d4acf07f219846638ebb00a68b76383c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea0d241aceabdb4e8ce126cddcb833827476c55bf5740d68ac8557d7f946988a8b6220a9f6d1939b51392b26ba189da5d6659df621cfd1643e6ac4d9d9434f81
|
7
|
+
data.tar.gz: ea7a7dae9e4aa1891d57eaaf2937ed37b8f2e81c6eff96b86ccab08ebed7dd7928e410baf6d5fc3f7100aa2dc0467af415c29946018c6757d9200bac76ce0299
|
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# Gkv
|
2
2
|
[![Join the chat at https://gitter.im/ybur-yug/gkv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ybur-yug/gkv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
3
|
+
<a href="https://codeclimate.com/github/ybur-yug/gkv"><img src="https://codeclimate.com/github/ybur-yug/gkv/badges/gpa.svg" /></a>
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/gkv.svg)](http://badge.fury.io/rb/gkv)
|
5
|
+
[![Build Status](https://travis-ci.org/ybur-yug/gkv.svg?branch=master)](https://travis-ci.org/ybur-yug/gkv)
|
6
|
+
|
3
7
|
|
4
8
|
Gkv is a simple git wrapper that allows you to use it as a kv store
|
5
9
|
|
6
10
|
![proof in our pudding](http://i.imgur.com/EKdt7oR.png)
|
7
11
|
|
8
|
-
|
12
|
+
[![asciicast](https://asciinema.org/a/a157ouz4ju5cy9v5r3pexhj4k.png)](https://asciinema.org/a/a157ouz4ju5cy9v5r3pexhj4k)
|
9
13
|
|
10
|
-
|
14
|
+
The documentation says thats what it does. So why not yo?
|
11
15
|
|
12
16
|
#### This is the product of a [tutorial](https://github.com/ybur-yug/git_kv_store_tutorial) I wrote to explore git.
|
13
17
|
|
@@ -28,10 +32,21 @@ Or install it yourself as:
|
|
28
32
|
$ gem install gkv
|
29
33
|
|
30
34
|
## API
|
35
|
+
Types are implicitly understood, and are automatically set/loaded. Only symbols are excluded.
|
31
36
|
There are 4 main functions:
|
32
37
|
|
33
38
|
### Set
|
34
39
|
|
40
|
+
db[*key*] = *value*
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
db = Gkv::Database.new
|
44
|
+
db['Pants'] = 'red leather'
|
45
|
+
# => 'red leather'
|
46
|
+
```
|
47
|
+
This allows a shorthand notation using operator overloading to set without invoking `set` directly.
|
48
|
+
|
49
|
+
|
35
50
|
set(*key*, *value*)
|
36
51
|
|
37
52
|
```ruby
|
@@ -43,6 +58,17 @@ db.set('test', 12)
|
|
43
58
|
```
|
44
59
|
|
45
60
|
### Get
|
61
|
+
|
62
|
+
db[*key*]
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
db = Gkv::Database.new
|
66
|
+
db['Pants']
|
67
|
+
# => 'red leather'
|
68
|
+
```
|
69
|
+
This allows a shorthand notation using operator overloading to get without invoking `get` directly.
|
70
|
+
|
71
|
+
|
46
72
|
get(*key*)
|
47
73
|
|
48
74
|
```ruby
|
@@ -87,8 +113,6 @@ db.all
|
|
87
113
|
|
88
114
|
## Usage
|
89
115
|
|
90
|
-
[![asciicast](https://asciinema.org/a/0ss6cqmm6yhnyvz88bdy37oiq.png)](https://asciinema.org/a/0ss6cqmm6yhnyvz88bdy37oiq)
|
91
|
-
|
92
116
|
```ruby
|
93
117
|
db = Gkv::Database.new
|
94
118
|
|
data/bench.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'gkv'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
gkv = Gkv::Database.new
|
5
|
+
|
6
|
+
n = 1000
|
7
|
+
|
8
|
+
Benchmark.bm do |x|
|
9
|
+
x.report("set:\t\t") { n.times { gkv.set('Apple', 10) } }
|
10
|
+
x.report("hash set:\t") { n.times { gkv['Apple'] = 10 } }
|
11
|
+
x.report("get:\t\t") { n.times { gkv.get('Apple') } }
|
12
|
+
x.report("hash get:\t") { n.times { gkv['Apple'] } }
|
13
|
+
end
|
data/example/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Usage
|
2
|
+
|
3
|
+
## Setup
|
4
|
+
Start the server
|
5
|
+
|
6
|
+
$ bundle
|
7
|
+
$ ruby server.rb
|
8
|
+
|
9
|
+
With this, in another terminal start IRB:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'net/http'
|
13
|
+
require 'uri'
|
14
|
+
|
15
|
+
set_uri = URI('http://localhost:4567/set')
|
16
|
+
get_uri = URI('http://localhost:4567/get')
|
17
|
+
|
18
|
+
set_params = { :key => 'your_key', :value => 'your value' }
|
19
|
+
get_params = { :key => 'your_key' }
|
20
|
+
set_uri.query = URI.encode_www_form(set_params)
|
21
|
+
get_uri.query = URI.encode_www_form(set_params)
|
22
|
+
|
23
|
+
set_resp = Net::HTTP.get(set_uri)
|
24
|
+
get_resp = Net::HTTP.get(get_uri)
|
25
|
+
puts set_resp
|
26
|
+
# => {"key_set":"your_key"}
|
27
|
+
puts get_resp
|
28
|
+
# => your value
|
29
|
+
```
|
data/example/server.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'json'
|
3
|
+
require 'gkv'
|
4
|
+
|
5
|
+
DB = Gkv::Database.new
|
6
|
+
|
7
|
+
get '/' do
|
8
|
+
{ all_items: DB.all }.to_json
|
9
|
+
end
|
10
|
+
|
11
|
+
get '/set' do
|
12
|
+
begin
|
13
|
+
key, value = params.fetch('key'), params.fetch('value')
|
14
|
+
DB.set(key, value)
|
15
|
+
{ key_set: key }.to_json
|
16
|
+
rescue KeyError
|
17
|
+
{ error: 'error setting key/value pair, please send key and value params' }.to_json
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/get' do
|
22
|
+
begin
|
23
|
+
key = params.fetch('key')
|
24
|
+
DB.get(key)
|
25
|
+
rescue KeyError
|
26
|
+
{ error: 'error retrieving key. it either does not exist or you did not send a parameter `key`' }.to_json
|
27
|
+
end
|
28
|
+
end
|
data/lib/gkv/database.rb
CHANGED
@@ -16,6 +16,10 @@ module Gkv
|
|
16
16
|
key
|
17
17
|
end
|
18
18
|
|
19
|
+
def []=(key, value)
|
20
|
+
set(key, value)
|
21
|
+
end
|
22
|
+
|
19
23
|
def get(key)
|
20
24
|
if $ITEMS.keys.include? key
|
21
25
|
YAML.load(Gkv::GitFunctions.cat_file($ITEMS[key].last))
|
@@ -24,6 +28,10 @@ module Gkv
|
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
31
|
+
def [](key)
|
32
|
+
get(key)
|
33
|
+
end
|
34
|
+
|
27
35
|
def get_version(version, key)
|
28
36
|
YAML.load(Gkv::GitFunctions.cat_file($ITEMS[key][version.to_i - 1]))
|
29
37
|
end
|
data/lib/gkv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gkv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '='
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,9 +83,12 @@ files:
|
|
83
83
|
- LICENSE.txt
|
84
84
|
- README.md
|
85
85
|
- Rakefile
|
86
|
+
- bench.rb
|
86
87
|
- bin/console
|
87
88
|
- bin/gkv
|
88
89
|
- bin/setup
|
90
|
+
- example/README.md
|
91
|
+
- example/server.rb
|
89
92
|
- gkv.gemspec
|
90
93
|
- lib/gkv.rb
|
91
94
|
- lib/gkv/database.rb
|