mm_to_view_model 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mm_to_view_model (0.1.1)
5
+ mongo_mapper (~> 0.9.2)
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
@@ -19,7 +25,9 @@ GEM
19
25
  rspec-instafail (~> 0.1.8)
20
26
  ruby-progressbar (~> 0.0.10)
21
27
  i18n (0.6.0)
22
- mocha (0.9.12)
28
+ metaclass (0.0.1)
29
+ mocha (0.10.0)
30
+ metaclass (~> 0.0.1)
23
31
  mongo (1.4.0)
24
32
  bson (= 1.4.0)
25
33
  mongo_mapper (0.9.2)
@@ -46,8 +54,9 @@ PLATFORMS
46
54
  ruby
47
55
 
48
56
  DEPENDENCIES
49
- fuubar
50
- mocha
51
- mongo_mapper
52
- rspec
53
- watchr
57
+ bundler (~> 1.0.0)
58
+ fuubar (~> 0.0.6)
59
+ mm_to_view_model!
60
+ mocha (~> 0.10.0)
61
+ rspec (~> 2.6.0)
62
+ watchr (~> 0.7.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,6 +1,5 @@
1
1
  require 'bundler/setup'
2
- Bundler.require(:default)
3
- # require 'active_support/core_ext/string'
2
+ require 'mongo_mapper'
4
3
 
5
4
  module MongoMapper
6
5
  module Plugins
@@ -13,8 +12,23 @@ module MongoMapper
13
12
  memo[k.to_s] = if v.type == ObjectId
14
13
  nil
15
14
  else
16
- v.type.new rescue nil
15
+ begin
16
+ unless v.default_value.nil?
17
+ v.default_value
18
+ else
19
+ v.type.new
20
+ end
21
+ rescue
22
+ nil
23
+ end
17
24
  end
25
+
26
+ begin
27
+ memo[k.to_s] = memo[k.to_s].class.from_mongo(memo[k.to_s])
28
+ rescue
29
+ # keep the unconverted version
30
+ end
31
+
18
32
  memo
19
33
  end
20
34
 
@@ -31,6 +45,13 @@ module MongoMapper
31
45
  def to_view_model
32
46
  fields = keys.inject({}) do |memo, (k, v)|
33
47
  memo[k.to_s] = send(k)
48
+
49
+ begin
50
+ memo[k.to_s] = memo[k.to_s].class.from_mongo(memo[k.to_s])
51
+ rescue
52
+ # keep the unconverted version
53
+ end
54
+
34
55
  memo
35
56
  end
36
57
 
@@ -6,6 +6,7 @@ class User
6
6
 
7
7
  key :name, String
8
8
  key :hobbies, Array
9
+ key :unemployed, Boolean, :default => false
9
10
 
10
11
  many :posts
11
12
  end
@@ -30,6 +31,7 @@ describe User do
30
31
  "_id" => nil,
31
32
  "name" => "",
32
33
  "hobbies" => [],
34
+ "unemployed" => false,
33
35
  "posts" => [
34
36
  { "_id" => nil, "title" => "", "body" => "" }
35
37
  ]
@@ -51,7 +53,8 @@ describe User do
51
53
  subject do
52
54
  User.new(
53
55
  "name" => "SomeBrodi12",
54
- "posts" => [first_post, second_post]
56
+ "posts" => [first_post, second_post],
57
+ "unemployed" => false
55
58
  )
56
59
  end
57
60
 
@@ -60,6 +63,7 @@ describe User do
60
63
  "_id" => subject.id,
61
64
  "name" => "SomeBrodi12",
62
65
  "hobbies" => [],
66
+ "unemployed" => false,
63
67
  "posts" => [
64
68
  { "_id" => first_post.id, "title" => "Some new cool thing", "body" => "This new cool thing rocks!", "user_id" => subject.id },
65
69
  { "_id" => second_post.id, "title" => "News about Paris", "body" => "They remade the eiffel tower out of cheese!", "user_id" => subject.id },
@@ -7,7 +7,6 @@ MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
7
7
  RSpec.configure do |config|
8
8
  config.before(:each) do
9
9
  MongoMapper.database.collections.each { |collection| collection.remove }.collect(&:name)
10
- system("clear")
11
10
  end
12
11
  end
13
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm_to_view_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo_mapper
16
- requirement: &70359705826240 !ruby/object:Gem::Requirement
16
+ requirement: &70149344652140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70359705826240
24
+ version_requirements: *70149344652140
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &70149344651640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70149344651640
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- requirement: &70359705825760 !ruby/object:Gem::Requirement
38
+ requirement: &70149344651180 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ~>
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: 2.6.0
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70359705825760
46
+ version_requirements: *70149344651180
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: mocha
38
- requirement: &70359705825280 !ruby/object:Gem::Requirement
49
+ requirement: &70149344650700 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 0.10.0
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70359705825280
57
+ version_requirements: *70149344650700
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: fuubar
49
- requirement: &70359705824740 !ruby/object:Gem::Requirement
60
+ requirement: &70149344650240 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: 0.0.6
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70359705824740
68
+ version_requirements: *70149344650240
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: watchr
60
- requirement: &70359705824260 !ruby/object:Gem::Requirement
71
+ requirement: &70149344649740 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ~>
@@ -65,7 +76,7 @@ dependencies:
65
76
  version: 0.7.0
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70359705824260
79
+ version_requirements: *70149344649740
69
80
  description: ! '`mm_to_view_model` is a `MongoMapper` plugin that adds a `to_view_model`
70
81
  class and instance method.'
71
82
  email: c00lryguy@gmail.com