jugyo-kvs 0.2.3 → 0.3.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.
Files changed (3) hide show
  1. data/lib/kvs.rb +4 -3
  2. data/spec/kvs_spec.rb +5 -5
  3. metadata +1 -1
data/lib/kvs.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'digest/sha1'
2
+ require 'yaml'
2
3
 
3
4
  module KVS
4
- VERSION = '0.2.3'
5
+ VERSION = '0.3.0'
5
6
 
6
7
  class <<self
7
8
  attr_accessor :dir
@@ -15,11 +16,11 @@ module KVS
15
16
  def [](key)
16
17
  path = file_of(key)
17
18
  return nil unless File.exists?(path)
18
- File.read(path)
19
+ YAML.load(File.read(path))
19
20
  end
20
21
 
21
22
  def []=(key, value)
22
- File.open(file_of(key), 'wb') { |f| f << value.to_s }
23
+ File.open(file_of(key), 'wb') { |f| f << value.to_yaml }
23
24
  end
24
25
 
25
26
  def delete(key)
data/spec/kvs_spec.rb CHANGED
@@ -16,14 +16,14 @@ describe KVS do
16
16
  end
17
17
 
18
18
  it 'should store data' do
19
- KVS['foo'] = 'bar'
20
- KVS['foo'].should == 'bar'
19
+ KVS['foo'] = {:a => 'b', :c => 'd'}
20
+ KVS['foo'].should == {:a => 'b', :c => 'd'}
21
21
  File.exists?(KVS.file_of('foo')).should be_true
22
22
  end
23
23
 
24
24
  it 'should store data with "<<"' do
25
- key = KVS << 'test'
26
- KVS[key].should == 'test'
25
+ key = KVS << {:a => 'b', :c => 'd'}
26
+ KVS[key].should == {:a => 'b', :c => 'd'}
27
27
  File.exists?(KVS.file_of(key)).should be_true
28
28
  end
29
29
 
@@ -78,7 +78,7 @@ describe KVS do
78
78
  end
79
79
 
80
80
  it 'should raise ArgumentError' do
81
- lambda { KVS['foo'] = 'bar' }.should raise_error(RuntimeError)
81
+ lambda { KVS['foo'] = {:a => 'b'} }.should raise_error(RuntimeError)
82
82
  lambda { KVS['foo'] }.should raise_error(RuntimeError)
83
83
  end
84
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jugyo-kvs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo