mongoo 0.4.6 → 0.4.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.6
1
+ 0.4.7
@@ -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].collect { |h| build(h) }
26
+ if res = raw[min..max]
27
+ res.collect { |h| build(h) }
28
+ end
21
29
  end
22
30
 
23
31
  def all
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoo}
8
- s.version = "0.4.6"
8
+ s.version = "0.4.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Myles"]
@@ -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((g('chapters') || s('chapters',[])), Book::Chapter)
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((g('authors') || s('authors', {})), Book::Author)
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((g('sample_chapter') || s('sample_chapter', {})), Book::Chapter)
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.6
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: -2643579001889888610
192
+ hash: 2470312361995980630
193
193
  segments:
194
194
  - 0
195
195
  version: "0"