gkv 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +119 -0
- data/Rakefile +6 -0
- data/bin/console +9 -0
- data/bin/gkv +3 -0
- data/bin/setup +7 -0
- data/gkv.gemspec +29 -0
- data/lib/gkv.rb +6 -0
- data/lib/gkv/database.rb +29 -0
- data/lib/gkv/git.rb +32 -0
- data/lib/gkv/version.rb +3 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e7086ff4e33f99aaff34e5eb12b442d856450c3
|
4
|
+
data.tar.gz: 18ed48d3a23cdbff795a52585df57a4c5290e065
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 719eb2aab72564f373356d43b8404ff06635546848f5d85edc9664f204940dd48d85b59013b89a169fc83343f1b14b92a05992c63725251243dddb49930413c8
|
7
|
+
data.tar.gz: 48bf8e3495393f8f1f162531b17a4e998d517ccbb78ce34918c088c95770913303fe8375ca4f18899f458daa55f39be2cf35e3c124a1825c3db671fe81d9cb7f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
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/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
2
|
+
Version 2, December 2004
|
3
|
+
|
4
|
+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
7
|
+
copies of this license document, and changing it is allowed as long
|
8
|
+
as the name is changed.
|
9
|
+
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Gkv
|
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
|
+
|
4
|
+
Gkv is a simple git wrapper that allows you to use it as a kv store
|
5
|
+
|
6
|
+
#### DO NOT use this in real software at its current state.
|
7
|
+
|
8
|
+
#### This is the product of a [tutorial](https://github.com/ybur-yug/git_kv_store_tutorial) I wrote to explore git.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'gkv'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install gkv
|
25
|
+
|
26
|
+
## API
|
27
|
+
There are 3 main functions:
|
28
|
+
|
29
|
+
### Set
|
30
|
+
|
31
|
+
set(*key*, *value*)
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
db = Gkv::Database.new
|
35
|
+
db.set('key', 12)
|
36
|
+
# input is all coerced to the string type and returned when set
|
37
|
+
# => '12'
|
38
|
+
```
|
39
|
+
|
40
|
+
### Get
|
41
|
+
get(*key*)
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
db = Gkv::Database.new
|
45
|
+
db.set('apples', '10')
|
46
|
+
# => '10'
|
47
|
+
db.get('apples')
|
48
|
+
# => '10'
|
49
|
+
```
|
50
|
+
|
51
|
+
### Get Version
|
52
|
+
|
53
|
+
get_version(*version*, *key*)
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
db = Gkv::Database.new
|
57
|
+
db.set('apples', '20')
|
58
|
+
db.set('apples', '50')
|
59
|
+
db.get_version(1, 'apples')
|
60
|
+
# => '20'
|
61
|
+
db.get_version(2, 'apples')
|
62
|
+
# => '50'
|
63
|
+
```
|
64
|
+
|
65
|
+
## Usage
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
db = Gkv::Database.new
|
69
|
+
|
70
|
+
db.set("Apples", "10")
|
71
|
+
db.get("Apples")
|
72
|
+
# => "10"
|
73
|
+
|
74
|
+
# update some values
|
75
|
+
db.set("Apples", "12")
|
76
|
+
db.get("Apples")
|
77
|
+
# => "12"
|
78
|
+
db.get_version(1, "Apples")
|
79
|
+
#=> 10
|
80
|
+
|
81
|
+
# keys that do not exist return KeyError
|
82
|
+
db.get('magic')
|
83
|
+
# => KeyError
|
84
|
+
|
85
|
+
# using it in sinatra
|
86
|
+
require 'sinatra'
|
87
|
+
require 'json'
|
88
|
+
|
89
|
+
post '/' do
|
90
|
+
db.set(params['key'], params['value')
|
91
|
+
{ msg: "#{params['key']} set to #{params['value']}" }.to_json
|
92
|
+
rescue
|
93
|
+
{ error: "Please send key and value params" }.to_json
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
get '/get/:key' do
|
98
|
+
{ key: db.get(params['key']) }.to_json
|
99
|
+
end
|
100
|
+
```
|
101
|
+
## Development
|
102
|
+
|
103
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the
|
104
|
+
tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
105
|
+
|
106
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version,
|
107
|
+
update the version number in `version.rb`, and then run `bundle exec rake release`, which will create
|
108
|
+
a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
109
|
+
|
110
|
+
## Contributing
|
111
|
+
Feel free to check out the gitter room and ask whats on the agenda.
|
112
|
+
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ybur-yug/gkv. This project is
|
114
|
+
intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
|
115
|
+
the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
See [this](http://www.wtfpl.net/about/).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/gkv
ADDED
data/bin/setup
ADDED
data/gkv.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gkv/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gkv"
|
8
|
+
spec.version = Gkv::VERSION
|
9
|
+
spec.authors = ["="]
|
10
|
+
spec.email = ["="]
|
11
|
+
|
12
|
+
spec.summary = %q{Git as a key:value store.}
|
13
|
+
spec.description = %q{Utilize a git repository as a trivially simple kv store.}
|
14
|
+
spec.homepage = "https://www.github.com/ybur-yug/gkv"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = "bin"
|
22
|
+
spec.executables = "gkv"
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
end
|
data/lib/gkv.rb
ADDED
data/lib/gkv/database.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$items = {}
|
2
|
+
module Gkv
|
3
|
+
class Database
|
4
|
+
include Gkv::DbFunctions
|
5
|
+
include Gkv::GitFunctions
|
6
|
+
attr_accessor :items
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
`git init`
|
10
|
+
end
|
11
|
+
|
12
|
+
def set(key, value)
|
13
|
+
update_items(key, value)
|
14
|
+
value
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(key)
|
18
|
+
if $items.keys.include? key
|
19
|
+
cat_file($items.fetch(key.to_s).last)
|
20
|
+
else
|
21
|
+
raise KeyError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_version(version, key)
|
26
|
+
cat_file($items[key][version.to_i - 1])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/gkv/git.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Gkv
|
2
|
+
module GitFunctions
|
3
|
+
def self.hash_object(data)
|
4
|
+
write_tmpfile(data)
|
5
|
+
hash = `git hash-object -w tmp.txt`.strip!
|
6
|
+
File.delete('tmp.txt')
|
7
|
+
hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.write_tmpfile(data)
|
11
|
+
f = File.open('tmp.txt', 'w+')
|
12
|
+
f.write(data.to_s)
|
13
|
+
f.close
|
14
|
+
end
|
15
|
+
|
16
|
+
def cat_file(hash)
|
17
|
+
`git cat-file -p #{hash}`
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module DbFunctions
|
22
|
+
def update_items(key, value)
|
23
|
+
if $items.keys.include? key
|
24
|
+
history = $items[key]
|
25
|
+
history << Gkv::GitFunctions.hash_object(value.to_s)
|
26
|
+
$items[key] = history
|
27
|
+
else
|
28
|
+
$items[key] = [Gkv::GitFunctions.hash_object(value.to_s)]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/gkv/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gkv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- '='
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Utilize a git repository as a trivially simple kv store.
|
70
|
+
email:
|
71
|
+
- '='
|
72
|
+
executables:
|
73
|
+
- gkv
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/gkv
|
87
|
+
- bin/setup
|
88
|
+
- gkv.gemspec
|
89
|
+
- lib/gkv.rb
|
90
|
+
- lib/gkv/database.rb
|
91
|
+
- lib/gkv/git.rb
|
92
|
+
- lib/gkv/version.rb
|
93
|
+
homepage: https://www.github.com/ybur-yug/gkv
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.8
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Git as a key:value store.
|
117
|
+
test_files: []
|