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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 431ffdcd55686613c8dec5a08c52a30dc7f7b3a2
4
- data.tar.gz: 7386ee297118d07e28e5b4dc21c2ec8809d38d9f
3
+ metadata.gz: 6f2467eb9e1eae31b24010118d048f02be7ef4ad
4
+ data.tar.gz: 238c0c1b4a9accb2bab30f1533a4beaf94690fb7
5
5
  SHA512:
6
- metadata.gz: 4bac8fe3dc27c0556ea6ecbf09c77d5ed7eea866659d37ca3b9bf8a0d9fc17f3c38a302a0b9c86cba4c0856fe3203fb241a497e149dd2e7a24d30288e1342535
7
- data.tar.gz: e96f636090b22f61b489779d47898b2745496950331199860a4f98080c1dc87d325583447d964f7a5a4d3bd8add5ca830e3991db6a343ea16acee4efe8531242
6
+ metadata.gz: 628ca18afc81b505d2786f3c37b2f5e1fac9d2c6f81bcd10db673d586115d8477d3831ec5aa518afb6f6149a2bca2d96294987f3d06de45cf61e093a7c7c546e
7
+ data.tar.gz: 5830828a11a1cf039ae6b47a28c4a6027fc37dd87ab7479e4441e59137c43a4014cba79ae73fbadf741f56ab239f1723ee34f863e0f39fe989fe2b7102f3dda6
@@ -0,0 +1,5 @@
1
+ v2.2.x
2
+ Full type system. All bugs related to hashes from 0.2.0 and 0.2.1 fixed.
3
+
4
+ v0.1.x
5
+ Set strings. Get strings
@@ -1,13 +1 @@
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/)
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 3 main functions:
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
- # input is all coerced to the string type and returned when set
37
- # => 'some_hash'
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
- # => 'some_hash'
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
- # => some_hash
67
+ # => 'apples'
59
68
  db.set('apples', '50')
60
- # => some_hash
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("Apples", "10")
73
- # => some_hash
74
- db.get("Apples")
75
- # => "10"
95
+ db.set('Apples', '10')
96
+ # => 'Apples'
97
+ db.get('Apples')
98
+ # => '10'
76
99
 
77
100
  # update some values
78
- db.set("Apples", "12")
79
- # => some_hash
80
- db.get("Apples")
81
- # => "12"
82
- db.get_version(1, "Apples")
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 rspec` to run the
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,
@@ -1,8 +1,10 @@
1
- $items = {}
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
- value
15
+ update_items(key, YAML.dump(value))
16
+ key
15
17
  end
16
18
 
17
19
  def get(key)
18
- if $items.keys.include? key
19
- cat_file($items.fetch(key.to_s).last)
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($items[key][version.to_i - 1])
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
@@ -1,15 +1,17 @@
1
1
  module Gkv
2
2
  module GitFunctions
3
- def self.hash_object(data)
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 self.write_tmpfile(data)
12
+ def write_tmpfile(data)
11
13
  f = File.open('tmp.txt', 'w+')
12
- f.write(data.to_s)
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 $items.keys.include? key
24
- history = $items[key]
25
- history << Gkv::GitFunctions.hash_object(value.to_s)
26
- $items[key] = history
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
- $items[key] = [Gkv::GitFunctions.hash_object(value.to_s)]
30
+ $ITEMS[key] = [Gkv::GitFunctions.hash_object(value)]
29
31
  end
30
32
  end
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module Gkv
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.2'
3
3
  end
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.1.1
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-17 00:00:00.000000000 Z
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
@@ -1,5 +0,0 @@
1
- # A sample Gemfile
2
- source "https://rubygems.org"
3
-
4
- gem "gkv"
5
- gem "sinatra"
@@ -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