store-memory 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/store/memory/version.rb +1 -1
- data/lib/store/memory.rb +26 -8
- data/spec/memory_hash_dupper_spec.rb +47 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 784af34035d8ceeb3f47cb7c46bd4e49d6118dd6
|
4
|
+
data.tar.gz: 8b72b6e11e43b9e7945afbf0477d8e095bad5ef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1826e00cc6ab24ff7bbd9961f09f081e4d0e6cffa0a0cbbb4a1b486612da833fba38acd5f1473b288366356bcf4d11b16980f7aa2af41b71e6982176c9f53878
|
7
|
+
data.tar.gz: bd8cfd07d881403cd635e6d10b0a39a09ebb06bdf0f5cf2003490f302f46df365c08b382801608b40683f927da081376cad1d4599517524e5bc100fcee9826f4
|
data/lib/store/memory/version.rb
CHANGED
data/lib/store/memory.rb
CHANGED
@@ -62,19 +62,37 @@ class Store
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def dup(data)
|
65
|
-
data and
|
65
|
+
data and HashDupper.dup(data)
|
66
66
|
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
hash.
|
71
|
-
|
68
|
+
class HashDupper
|
69
|
+
def self.dup(hash)
|
70
|
+
new(hash).dup
|
71
|
+
end
|
72
|
+
|
73
|
+
def initialize(hash)
|
74
|
+
@hash = hash
|
75
|
+
end
|
76
|
+
|
77
|
+
def dup
|
78
|
+
Hash.new.tap do |dupped_hash|
|
79
|
+
@hash.each do |key, value|
|
80
|
+
dupped_hash[key] = dup_obj(value)
|
81
|
+
end
|
72
82
|
end
|
73
83
|
end
|
74
|
-
end
|
75
84
|
|
76
|
-
|
77
|
-
|
85
|
+
private
|
86
|
+
def dup_obj(obj)
|
87
|
+
case obj
|
88
|
+
when Symbol
|
89
|
+
obj
|
90
|
+
when nil
|
91
|
+
nil
|
92
|
+
else
|
93
|
+
obj.dup
|
94
|
+
end
|
95
|
+
end
|
78
96
|
end
|
79
97
|
|
80
98
|
def store(id, data)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Store::DataMapper::Memory::HashDupper do
|
4
|
+
|
5
|
+
it 'dups simple string hashes' do
|
6
|
+
hash = {
|
7
|
+
'a' => "ABC"
|
8
|
+
}
|
9
|
+
|
10
|
+
dupped_hash = duplicate(hash)
|
11
|
+
|
12
|
+
dupped_hash['a'].gsub!('A', 'a')
|
13
|
+
|
14
|
+
assert_equal 'ABC', hash['a']
|
15
|
+
assert_equal 'aBC', dupped_hash['a']
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'dups simple symbol hashes' do
|
19
|
+
hash = {
|
20
|
+
:a => "ABC"
|
21
|
+
}
|
22
|
+
|
23
|
+
dupped_hash = duplicate(hash)
|
24
|
+
|
25
|
+
dupped_hash[:a].gsub!('A', 'a')
|
26
|
+
|
27
|
+
assert_equal 'ABC', hash[:a]
|
28
|
+
assert_equal 'aBC', dupped_hash[:a]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can process symbolic values' do
|
32
|
+
hash = {
|
33
|
+
'a' => :symbol1
|
34
|
+
}
|
35
|
+
|
36
|
+
dupped_hash = duplicate(hash)
|
37
|
+
|
38
|
+
assert_equal :symbol1, dupped_hash['a']
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
private
|
44
|
+
def duplicate(hash)
|
45
|
+
Store::DataMapper::Memory::HashDupper.dup(hash)
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store-memory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Owiesniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/store/memory.rb
|
97
97
|
- lib/store/memory/version.rb
|
98
98
|
- spec/helper.rb
|
99
|
+
- spec/memory_hash_dupper_spec.rb
|
99
100
|
- spec/memory_spec.rb
|
100
101
|
- store-memory.gemspec
|
101
102
|
homepage: ''
|
@@ -124,4 +125,5 @@ specification_version: 4
|
|
124
125
|
summary: Basic Memory DataMapper for Store.
|
125
126
|
test_files:
|
126
127
|
- spec/helper.rb
|
128
|
+
- spec/memory_hash_dupper_spec.rb
|
127
129
|
- spec/memory_spec.rb
|