mongoid-casino 0.0.2 → 0.0.3
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.
- data/lib/casino/store.rb +16 -1
- data/lib/casino/version.rb +1 -1
- data/spec/lib/casino/store_spec.rb +4 -4
- metadata +2 -2
data/lib/casino/store.rb
CHANGED
@@ -23,6 +23,7 @@ module Casino
|
|
23
23
|
|
24
24
|
def merge(*documents)
|
25
25
|
documents.each do |document|
|
26
|
+
document = mongoize document
|
26
27
|
criteria = find _id: document['_id']
|
27
28
|
criteria.upsert document
|
28
29
|
end
|
@@ -32,6 +33,10 @@ module Casino
|
|
32
33
|
@criteria ||= build_criteria
|
33
34
|
end
|
34
35
|
|
36
|
+
def mongoize(hash)
|
37
|
+
hash.keys.map { |key| build_mongoized_hash(hash, key) }.reduce(&:merge)
|
38
|
+
end
|
39
|
+
|
35
40
|
private
|
36
41
|
|
37
42
|
def session
|
@@ -45,5 +50,15 @@ module Casino
|
|
45
50
|
klass.scoped
|
46
51
|
end
|
47
52
|
|
53
|
+
def evolve(value)
|
54
|
+
value.class.respond_to?(:evolve) ? value.class.evolve(value) : value
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_mongoized_hash(hash, key)
|
58
|
+
value = hash[key]
|
59
|
+
value = value.is_a?(Hash) ? mongoize(value) : value
|
60
|
+
{ key => evolve(value) }
|
61
|
+
end
|
62
|
+
|
48
63
|
end
|
49
|
-
end
|
64
|
+
end
|
data/lib/casino/version.rb
CHANGED
@@ -24,11 +24,11 @@ describe Casino::Store do
|
|
24
24
|
describe '#merge' do
|
25
25
|
|
26
26
|
let(:womens_boots) do
|
27
|
-
{ '_id' => { 'date' =>
|
27
|
+
{ '_id' => { 'date' => Date.today, 'label' => "women's boots" } }
|
28
28
|
end
|
29
29
|
|
30
30
|
let(:mens_boots) do
|
31
|
-
{ '_id' => { 'date' =>
|
31
|
+
{ '_id' => { 'date' => Date.today, 'label' => "men's boots" } }
|
32
32
|
end
|
33
33
|
|
34
34
|
let(:value_hash) do
|
@@ -40,7 +40,7 @@ describe Casino::Store do
|
|
40
40
|
|
41
41
|
it "adds new documents to the collection" do
|
42
42
|
store.merge(document)
|
43
|
-
store.first.must_equal document
|
43
|
+
store.first.must_equal store.mongoize(document)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "updates documents" do
|
@@ -57,4 +57,4 @@ describe Casino::Store do
|
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
-
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-casino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|