mongodb_model 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake_ext'
2
2
 
3
3
  project(
4
4
  name: "mongodb_model",
5
- version: '0.2.1',
5
+ # version: '0.2.1',
6
6
  gem: true,
7
7
  summary: "Object Model for MongoDB",
8
8
 
@@ -0,0 +1,32 @@
1
+ Validatable::Errors.class_eval do
2
+ def full_messages
3
+ collect do |attribute, messages|
4
+ if attribute == :base
5
+ messages
6
+ else
7
+ attribute = attribute.to_s.humanize
8
+ messages.collect{|message| "#{attribute} #{message}"}
9
+ end
10
+ end.flatten
11
+ end
12
+ end
13
+
14
+ module Mongo::Model::Rails
15
+ def to_model; self end
16
+
17
+ def persisted?; !!_id end
18
+
19
+ def to_key
20
+ persisted? ? [_id] : nil
21
+ end
22
+
23
+ module ClassMethods
24
+ def model_name
25
+ @_model_name ||= begin
26
+ namespace = self.ancestors.detect { |n| n.respond_to?(:_railtie) }
27
+ ActiveModel::Name.new(self, namespace)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ Mongo::Model.inherit Mongo::Model::Rails
@@ -19,7 +19,7 @@ module Mongo::Model::Misc
19
19
  end
20
20
 
21
21
  def to_param
22
- (_id || '').to_s
22
+ _id.try :to_s
23
23
  end
24
24
 
25
25
  def reload
data/lib/mongo/model.rb CHANGED
@@ -47,4 +47,6 @@ Mongo.defaults.merge! \
47
47
  convert_underscore_to_dollar: true,
48
48
  batch_size: 50,
49
49
  multi: true,
50
- safe: true
50
+ safe: true
51
+
52
+ require 'mongo/model/integration/rails' if defined? Rails
data/spec/misc_spec.rb CHANGED
@@ -46,14 +46,14 @@ describe 'Model Miscellaneous' do
46
46
 
47
47
  it "to_param" do
48
48
  u = User.new
49
- u.to_param.should == ''
49
+ u.to_param.should be_nil
50
50
  u.save!
51
51
  u.to_param.should_not be_empty
52
52
  end
53
53
 
54
54
  it "dom_id" do
55
55
  u = User.new
56
- u.dom_id.should == ''
56
+ u.dom_id.should be_nil
57
57
  u.save!
58
58
  u.dom_id.should_not be_empty
59
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000Z
12
+ date: 2011-09-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongodb
16
- requirement: &2844160 !ruby/object:Gem::Requirement
16
+ requirement: &2840810 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2844160
24
+ version_requirements: *2840810
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: file_model
27
- requirement: &2843920 !ruby/object:Gem::Requirement
27
+ requirement: &2840570 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2843920
35
+ version_requirements: *2840570
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: validatable2
38
- requirement: &2843680 !ruby/object:Gem::Requirement
38
+ requirement: &2840330 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2843680
46
+ version_requirements: *2840330
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ruby_ext
49
- requirement: &2843440 !ruby/object:Gem::Requirement
49
+ requirement: &2840090 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2843440
57
+ version_requirements: *2840090
58
58
  description:
59
59
  email:
60
60
  executables: []
@@ -70,6 +70,7 @@ files:
70
70
  - lib/mongo/model/crud.rb
71
71
  - lib/mongo/model/db.rb
72
72
  - lib/mongo/model/file_model.rb
73
+ - lib/mongo/model/integration/rails.rb
73
74
  - lib/mongo/model/misc.rb
74
75
  - lib/mongo/model/model.rb
75
76
  - lib/mongo/model/query.rb