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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 806cb434064eadd4acdd0af34b53a4fc4ff040d6
4
- data.tar.gz: 6fc57977f5b5d89902434a3249001337520e1dc0
3
+ metadata.gz: 784af34035d8ceeb3f47cb7c46bd4e49d6118dd6
4
+ data.tar.gz: 8b72b6e11e43b9e7945afbf0477d8e095bad5ef7
5
5
  SHA512:
6
- metadata.gz: 4cd835f43fe2742a8bc10aeb1d65c98c56a83f82cc042c92d25d0aaeb539b423ea34b1fb1a880aab8063f9ed4dfd0c0d5e3f523c7707052923992837f6e5b62a
7
- data.tar.gz: 695ab1d5f54aec57841a1386ffb26d9e19ad03c1386cd39682c82046a166918e89dec12ed780b3092c23382069e09b0d940655acac5808958c3bac78ab58ccda
6
+ metadata.gz: 1826e00cc6ab24ff7bbd9961f09f081e4d0e6cffa0a0cbbb4a1b486612da833fba38acd5f1473b288366356bcf4d11b16980f7aa2af41b71e6982176c9f53878
7
+ data.tar.gz: bd8cfd07d881403cd635e6d10b0a39a09ebb06bdf0f5cf2003490f302f46df365c08b382801608b40683f927da081376cad1d4599517524e5bc100fcee9826f4
@@ -1,5 +1,5 @@
1
1
  class Store
2
2
  class Memory
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
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 dup_hash(data)
65
+ data and HashDupper.dup(data)
66
66
  end
67
67
 
68
- def dup_hash(hash)
69
- Hash.new.tap do |dupped_hash|
70
- hash.each do |key, value|
71
- dupped_hash[key] = dup_obj(value)
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
- def dup_obj(obj)
77
- obj ? obj.dup : nil
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
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-28 00:00:00.000000000 Z
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