gkv 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGLELOG +5 -0
- data/CODE_OF_CONDUCT.md +1 -13
- data/README.md +41 -20
- data/lib/gkv/database.rb +17 -7
- data/lib/gkv/git.rb +10 -8
- data/lib/gkv/version.rb +1 -1
- metadata +3 -5
- data/example_application/Gemfile +0 -5
- data/example_application/Gemfile.lock +0 -22
- data/example_application/server.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2467eb9e1eae31b24010118d048f02be7ef4ad
|
4
|
+
data.tar.gz: 238c0c1b4a9accb2bab30f1533a4beaf94690fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 628ca18afc81b505d2786f3c37b2f5e1fac9d2c6f81bcd10db673d586115d8477d3831ec5aa518afb6f6149a2bca2d96294987f3d06de45cf61e093a7c7c546e
|
7
|
+
data.tar.gz: 5830828a11a1cf039ae6b47a28c4a6027fc37dd87ab7479e4441e59137c43a4014cba79ae73fbadf741f56ab239f1723ee34f863e0f39fe989fe2b7102f3dda6
|
data/CHANGLELOG
ADDED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,13 +1 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
1
|
+
# [DWTFYW](http://www.wtfpl.net/)
|
data/README.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
|
4
4
|
Gkv is a simple git wrapper that allows you to use it as a kv store
|
5
5
|
|
6
|
+
![proof in our pudding](http://i.imgur.com/EKdt7oR.png)
|
7
|
+
|
8
|
+
The documentation says thats what it does. So why not yo?
|
9
|
+
|
6
10
|
#### DO NOT use this in real software at its current state.
|
7
11
|
|
8
12
|
#### This is the product of a [tutorial](https://github.com/ybur-yug/git_kv_store_tutorial) I wrote to explore git.
|
@@ -24,7 +28,7 @@ Or install it yourself as:
|
|
24
28
|
$ gem install gkv
|
25
29
|
|
26
30
|
## API
|
27
|
-
There are
|
31
|
+
There are 4 main functions:
|
28
32
|
|
29
33
|
### Set
|
30
34
|
|
@@ -32,9 +36,10 @@ set(*key*, *value*)
|
|
32
36
|
|
33
37
|
```ruby
|
34
38
|
db = Gkv::Database.new
|
35
|
-
db.set('key', 12)
|
36
|
-
#
|
37
|
-
|
39
|
+
db.set('key', '12')
|
40
|
+
# => 'key'
|
41
|
+
db.set('test', 12)
|
42
|
+
# => 'test'
|
38
43
|
```
|
39
44
|
|
40
45
|
### Get
|
@@ -43,11 +48,15 @@ get(*key*)
|
|
43
48
|
```ruby
|
44
49
|
db = Gkv::Database.new
|
45
50
|
db.set('apples', '10')
|
46
|
-
# => '
|
51
|
+
# => 'apples'
|
47
52
|
db.get('apples')
|
48
53
|
# => '10'
|
49
54
|
```
|
50
55
|
|
56
|
+
The type is inferred from when you initially set the value. Note that saving the string `'1'` will
|
57
|
+
return the integer `1` due to the naive nature of the implementation. Hashes, arrays and booleans
|
58
|
+
behave as expected when saved.
|
59
|
+
|
51
60
|
### Get Version
|
52
61
|
|
53
62
|
get_version(*version*, *key*)
|
@@ -55,43 +64,55 @@ get_version(*version*, *key*)
|
|
55
64
|
```ruby
|
56
65
|
db = Gkv::Database.new
|
57
66
|
db.set('apples', '20')
|
58
|
-
# =>
|
67
|
+
# => 'apples'
|
59
68
|
db.set('apples', '50')
|
60
|
-
# =>
|
69
|
+
# => 'apples'
|
61
70
|
db.get_version(1, 'apples')
|
62
71
|
# => '20'
|
63
72
|
db.get_version(2, 'apples')
|
64
73
|
# => '50'
|
65
74
|
```
|
66
75
|
|
76
|
+
### All
|
77
|
+
|
78
|
+
all
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
db.set('apples', 20.0)
|
82
|
+
db.set('ants', 'pants')
|
83
|
+
db.set('things', {})
|
84
|
+
db.all
|
85
|
+
# =>[{ 'apples': 20.0 }, { 'ants': 'pants'}, { 'things': {} }]
|
86
|
+
```
|
87
|
+
|
67
88
|
## Usage
|
68
89
|
|
90
|
+
[![asciicast](https://asciinema.org/a/0ss6cqmm6yhnyvz88bdy37oiq.png)](https://asciinema.org/a/0ss6cqmm6yhnyvz88bdy37oiq)
|
91
|
+
|
69
92
|
```ruby
|
70
93
|
db = Gkv::Database.new
|
71
94
|
|
72
|
-
db.set(
|
73
|
-
# =>
|
74
|
-
db.get(
|
75
|
-
# =>
|
95
|
+
db.set('Apples', '10')
|
96
|
+
# => 'Apples'
|
97
|
+
db.get('Apples')
|
98
|
+
# => '10'
|
76
99
|
|
77
100
|
# update some values
|
78
|
-
db.set(
|
79
|
-
# =>
|
80
|
-
db.get(
|
81
|
-
# =>
|
82
|
-
db.get_version(1,
|
83
|
-
#=> 10
|
101
|
+
db.set('Apples', '12')
|
102
|
+
# => 'Apples'
|
103
|
+
db.get('Apples')
|
104
|
+
# => '12'
|
105
|
+
db.get_version(1, 'Apples')
|
106
|
+
#=> '10'
|
84
107
|
|
85
108
|
# keys that do not exist return KeyError
|
86
109
|
db.get('magic')
|
87
110
|
# => KeyError
|
88
111
|
```
|
89
112
|
|
90
|
-
There is an example application included in the `example_app` directory that utilizes Sinatra
|
91
|
-
|
92
113
|
## Development
|
93
114
|
|
94
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
115
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the
|
95
116
|
tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
96
117
|
|
97
118
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version,
|
data/lib/gkv/database.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
$ITEMS = {}
|
4
|
+
|
2
5
|
module Gkv
|
3
6
|
class Database
|
4
7
|
include Gkv::DbFunctions
|
5
|
-
include Gkv::GitFunctions
|
6
8
|
attr_accessor :items
|
7
9
|
|
8
10
|
def initialize
|
@@ -10,20 +12,28 @@ module Gkv
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def set(key, value)
|
13
|
-
update_items(key, value)
|
14
|
-
|
15
|
+
update_items(key, YAML.dump(value))
|
16
|
+
key
|
15
17
|
end
|
16
18
|
|
17
19
|
def get(key)
|
18
|
-
if $
|
19
|
-
cat_file($
|
20
|
+
if $ITEMS.keys.include? key
|
21
|
+
YAML.load(Gkv::GitFunctions.cat_file($ITEMS[key].last))
|
20
22
|
else
|
21
23
|
raise KeyError
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def get_version(version, key)
|
26
|
-
cat_file($
|
28
|
+
YAML.load(Gkv::GitFunctions.cat_file($ITEMS[key][version.to_i - 1]))
|
29
|
+
end
|
30
|
+
|
31
|
+
def all
|
32
|
+
$ITEMS.keys.map { |key|
|
33
|
+
hash = $ITEMS[key].last
|
34
|
+
value = YAML.load(Gkv::GitFunctions.cat_file(hash))
|
35
|
+
{ "#{key}": value }
|
36
|
+
}
|
27
37
|
end
|
28
38
|
end
|
29
39
|
end
|
data/lib/gkv/git.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
module Gkv
|
2
2
|
module GitFunctions
|
3
|
-
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def hash_object(data)
|
4
6
|
write_tmpfile(data)
|
5
7
|
hash = `git hash-object -w tmp.txt`.strip!
|
6
8
|
File.delete('tmp.txt')
|
7
9
|
hash
|
8
10
|
end
|
9
11
|
|
10
|
-
def
|
12
|
+
def write_tmpfile(data)
|
11
13
|
f = File.open('tmp.txt', 'w+')
|
12
|
-
f.write(data
|
14
|
+
f.write(data)
|
13
15
|
f.close
|
14
16
|
end
|
15
17
|
|
@@ -20,12 +22,12 @@ module Gkv
|
|
20
22
|
|
21
23
|
module DbFunctions
|
22
24
|
def update_items(key, value)
|
23
|
-
if $
|
24
|
-
history = $
|
25
|
-
history << Gkv::GitFunctions.hash_object(value
|
26
|
-
$
|
25
|
+
if $ITEMS.keys.include? key
|
26
|
+
history = $ITEMS[key]
|
27
|
+
history << Gkv::GitFunctions.hash_object(value)
|
28
|
+
$ITEMS[key] = history
|
27
29
|
else
|
28
|
-
$
|
30
|
+
$ITEMS[key] = [Gkv::GitFunctions.hash_object(value)]
|
29
31
|
end
|
30
32
|
end
|
31
33
|
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.
|
4
|
+
version: 0.2.2
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".gitignore"
|
78
78
|
- ".rspec"
|
79
79
|
- ".travis.yml"
|
80
|
+
- CHANGLELOG
|
80
81
|
- CODE_OF_CONDUCT.md
|
81
82
|
- Gemfile
|
82
83
|
- LICENSE.txt
|
@@ -85,9 +86,6 @@ files:
|
|
85
86
|
- bin/console
|
86
87
|
- bin/gkv
|
87
88
|
- bin/setup
|
88
|
-
- example_application/Gemfile
|
89
|
-
- example_application/Gemfile.lock
|
90
|
-
- example_application/server.rb
|
91
89
|
- gkv.gemspec
|
92
90
|
- lib/gkv.rb
|
93
91
|
- lib/gkv/database.rb
|
data/example_application/Gemfile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
gkv (0.1.0)
|
5
|
-
rack (1.6.2)
|
6
|
-
rack-protection (1.5.3)
|
7
|
-
rack
|
8
|
-
sinatra (1.4.6)
|
9
|
-
rack (~> 1.4)
|
10
|
-
rack-protection (~> 1.4)
|
11
|
-
tilt (>= 1.3, < 3)
|
12
|
-
tilt (2.0.1)
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
gkv
|
19
|
-
sinatra
|
20
|
-
|
21
|
-
BUNDLED WITH
|
22
|
-
1.10.3
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'gkv'
|
2
|
-
require 'json'
|
3
|
-
require 'sinatra'
|
4
|
-
|
5
|
-
db = Gkv::Database.new
|
6
|
-
|
7
|
-
get '/get/:key' do
|
8
|
-
db.get(params['key'])
|
9
|
-
end
|
10
|
-
|
11
|
-
post '/set' do
|
12
|
-
begin
|
13
|
-
key, value = params.fetch('key'), params.fetch('value')
|
14
|
-
db.set(key, value)
|
15
|
-
rescue KeyError
|
16
|
-
{ error: 'Please send key and value params in your request' }.to_json
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# tuh duh
|