daybreak 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,43 @@
1
1
  module Daybreak
2
2
  module Serializer
3
+ # Serializer which only encodes key in binary
4
+ # @api public
5
+ class None
6
+ # (see Daybreak::Serializer::Default#key_for)
7
+ if ''.respond_to? :force_encoding
8
+ def key_for(key)
9
+ if key.encoding != Encoding::BINARY
10
+ key = key.dup if key.frozen?
11
+ key.force_encoding(Encoding::BINARY)
12
+ end
13
+ key
14
+ end
15
+ else
16
+ def key_for(key)
17
+ key
18
+ end
19
+ end
20
+
21
+ # (see Daybreak::Serializer::Default#dump)
22
+ def dump(value)
23
+ value
24
+ end
25
+
26
+ # (see Daybreak::Serializer::Default#load)
27
+ def load(value)
28
+ value
29
+ end
30
+ end
31
+
3
32
  # Default serializer which converts
4
33
  # keys to strings and marshalls values
5
34
  # @api public
6
- class Default
35
+ class Default < None
7
36
  # Transform the key to a string
8
37
  # @param [Object] key
9
38
  # @return [String] key transformed to string
10
39
  def key_for(key)
11
- key.to_s
40
+ super(key.to_s)
12
41
  end
13
42
 
14
43
  # Serialize a value
@@ -25,24 +54,5 @@ module Daybreak
25
54
  Marshal.load(value)
26
55
  end
27
56
  end
28
-
29
- # Serializer which does nothing
30
- # @api public
31
- class None
32
- # (see Daybreak::Serializer::Default#key_for)
33
- def key_for(key)
34
- key
35
- end
36
-
37
- # (see Daybreak::Serializer::Default#dump)
38
- def dump(value)
39
- value
40
- end
41
-
42
- # (see Daybreak::Serializer::Default#load)
43
- def load(value)
44
- value
45
- end
46
- end
47
57
  end
48
58
  end
@@ -1,5 +1,5 @@
1
1
  module Daybreak
2
2
  # Version string updated using SemVer
3
3
  # @api public
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/benchmark'
3
4
 
@@ -21,6 +22,13 @@ describe Daybreak::DB do
21
22
  assert_equal @db.length, 1
22
23
  end
23
24
 
25
+ it 'should support frozen key' do
26
+ key = 'key'
27
+ key.freeze
28
+ @db[key] = 'value'
29
+ assert_equal @db[key], 'value'
30
+ end
31
+
24
32
  it 'should support batch inserts' do
25
33
  @db.update(1 => :a, 2 => :b)
26
34
  assert_equal @db[1], :a
@@ -388,6 +396,14 @@ describe Daybreak::DB do
388
396
  assert @db.bytesize > 0
389
397
  end
390
398
 
399
+ it 'should accept utf-8 keys' do
400
+ @db['🌎'] = '🌎'
401
+ @db.flush
402
+ db = Daybreak::DB.new DB_PATH
403
+ assert_equal db['🌎'], '🌎'
404
+ db.close
405
+ end
406
+
391
407
  after do
392
408
  @db.clear
393
409
  @db.close
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daybreak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
4
  prerelease:
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeff Larson
@@ -10,40 +10,40 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-18 00:00:00.000000000 Z
13
+ date: 2013-01-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rake
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
16
+ version_requirements: !ruby/object:Gem::Requirement
19
17
  requirements:
20
18
  - - ! '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
21
+ none: false
22
+ name: rake
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
25
+ requirement: !ruby/object:Gem::Requirement
27
26
  requirements:
28
27
  - - ! '>='
29
28
  - !ruby/object:Gem::Version
30
29
  version: '0'
31
- - !ruby/object:Gem::Dependency
32
- name: minitest
33
- requirement: !ruby/object:Gem::Requirement
34
30
  none: false
31
+ - !ruby/object:Gem::Dependency
32
+ version_requirements: !ruby/object:Gem::Requirement
35
33
  requirements:
36
34
  - - ! '>='
37
35
  - !ruby/object:Gem::Version
38
36
  version: '0'
37
+ none: false
38
+ name: minitest
39
39
  type: :development
40
40
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
41
+ requirement: !ruby/object:Gem::Requirement
43
42
  requirements:
44
43
  - - ! '>='
45
44
  - !ruby/object:Gem::Version
46
45
  version: '0'
46
+ none: false
47
47
  description: Incredibly fast pure-ruby key-value store
48
48
  email:
49
49
  - thejefflarson@gmail.com
@@ -83,20 +83,20 @@ rdoc_options: []
83
83
  require_paths:
84
84
  - lib
85
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
- none: false
87
86
  requirements:
88
87
  - - ! '>='
89
88
  - !ruby/object:Gem::Version
90
89
  version: '0'
91
- required_rubygems_version: !ruby/object:Gem::Requirement
92
90
  none: false
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - ! '>='
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
96
+ none: false
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 1.8.24
99
+ rubygems_version: 1.8.23
100
100
  signing_key:
101
101
  specification_version: 3
102
102
  summary: Daybreak provides an incredibly fast pure-ruby in memory key-value store,
@@ -105,3 +105,4 @@ test_files:
105
105
  - test/prof.rb
106
106
  - test/test.rb
107
107
  - test/test_helper.rb
108
+ has_rdoc: