mongoo 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoo/core.rb +6 -0
- data/lib/mongoo/embedded/array_proxy.rb +9 -1
- data/mongoo.gemspec +1 -1
- data/test/test_embedded.rb +5 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.7
|
data/lib/mongoo/core.rb
CHANGED
@@ -112,6 +112,12 @@ module Mongoo
|
|
112
112
|
alias :set :set_attribute
|
113
113
|
alias :s :set_attribute
|
114
114
|
|
115
|
+
def get_or_set_attribute(k, v)
|
116
|
+
get_attribute(k) || set_attribute(k, v)
|
117
|
+
end
|
118
|
+
alias :get_or_set :get_or_set_attribute
|
119
|
+
alias :gs :get_or_set_attribute
|
120
|
+
|
115
121
|
def unset_attribute(k)
|
116
122
|
mongohash.dot_delete(k); true
|
117
123
|
end
|
@@ -16,8 +16,16 @@ module Mongoo
|
|
16
16
|
@array
|
17
17
|
end
|
18
18
|
|
19
|
+
def [](index)
|
20
|
+
if res = raw[index]
|
21
|
+
build(res)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
19
25
|
def range(min=0, max=-1)
|
20
|
-
raw[min..max]
|
26
|
+
if res = raw[min..max]
|
27
|
+
res.collect { |h| build(h) }
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
31
|
def all
|
data/mongoo.gemspec
CHANGED
data/test/test_embedded.rb
CHANGED
@@ -7,15 +7,15 @@ class Book < Mongoo::Base
|
|
7
7
|
attribute "sample_chapter", :type => :hash
|
8
8
|
|
9
9
|
def chapters
|
10
|
-
@chapters ||= embedded_array_proxy((
|
10
|
+
@chapters ||= embedded_array_proxy(get_or_set('chapters',[]), Book::Chapter)
|
11
11
|
end
|
12
12
|
|
13
13
|
def authors
|
14
|
-
@authors ||= embedded_hash_proxy((
|
14
|
+
@authors ||= embedded_hash_proxy(get_or_set('authors', {}), Book::Author)
|
15
15
|
end
|
16
16
|
|
17
17
|
def sample_chapter
|
18
|
-
@sample_chapter ||= embedded_doc((
|
18
|
+
@sample_chapter ||= embedded_doc(get_or_set('sample_chapter', {}), Book::Chapter)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -52,6 +52,8 @@ class TestEmbedded < Test::Unit::TestCase
|
|
52
52
|
assert_not_equal b.chapters.range(0,0), b2.chapters.range(0,0)
|
53
53
|
|
54
54
|
assert_equal 2, b2.chapters.size
|
55
|
+
|
56
|
+
assert_equal "How to Transcend Fear", b2.chapters[0].title
|
55
57
|
end
|
56
58
|
|
57
59
|
should "be able to work with embedded doc hashes" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mongoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Myles
|
@@ -189,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
189
|
requirements:
|
190
190
|
- - ">="
|
191
191
|
- !ruby/object:Gem::Version
|
192
|
-
hash:
|
192
|
+
hash: 2470312361995980630
|
193
193
|
segments:
|
194
194
|
- 0
|
195
195
|
version: "0"
|