mongomatic-rails3 0.0.1 → 0.0.2

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/README.rdoc CHANGED
@@ -53,4 +53,18 @@ will generate a class inheriting from Mongomatic::Base. Mongomatic supports per-
53
53
 
54
54
  ==== Scaffolds
55
55
 
56
- mongomatic-rails3 adds support for Scaffold generation, however, scaffold support is currently limited. This library does not *yet* support form_for, due to its hash-only data access syntax (you should instead use form_tag), which scaffolds generate in their views (*yet* will most likely mean a special form helper for Mongomatic). You can, however, still use scaffolds as a starting point.
56
+ mongomatic-rails3 adds support for Scaffold generation, however, scaffold support is currently limited. This library does not *yet* support form_for, due to its hash-only data access syntax (you should instead use form_tag), which scaffolds generate in their views (*yet* will most likely mean a special form helper for Mongomatic). You can, however, still use scaffolds as a starting point.
57
+
58
+ == Note on Patches/Pull Requests
59
+
60
+ * Fork the project.
61
+ * Make your feature addition or bug fix.
62
+ * Add tests for it. This is important so I don't break it in a
63
+ future version unintentionally.
64
+ * Commit, do not mess with rakefile, version, or history.
65
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
66
+ * Send me a pull request. Bonus points for topic branches.
67
+
68
+ == Copyright
69
+
70
+ Copyright (c) 2010 Jordan West. See LICENSE for details.
@@ -15,7 +15,7 @@ module Mongomatic
15
15
  end
16
16
 
17
17
  def self.find(klass, params=nil)
18
- (params.blank?) ? "#{klass}.find" : "#{klass}.find_one(BSON::ObjectID(#{params}))"
18
+ (params.blank?) ? "#{klass}.find" : "#{klass}.find_one(BSON::ObjectId(#{params}))"
19
19
  end
20
20
 
21
21
  def self.build(klass, params=nil)
@@ -3,22 +3,7 @@ module Rails
3
3
  module Support
4
4
  def self.included(base)
5
5
  base.extend ClassMethods
6
- end
7
-
8
- def new_record?
9
- new?
10
- end
11
-
12
- def persisted?
13
- !(new? || removed?)
14
- end
15
-
16
- def to_key
17
- (new_record?) ? nil : [to_param]
18
- end
19
-
20
- def to_param
21
- self['_id'].to_s
6
+ ::Mongomatic::Errors.send(:include, Errors)
22
7
  end
23
8
 
24
9
  def merge!(hash)
@@ -27,11 +12,37 @@ module Rails
27
12
  update
28
13
  end
29
14
 
15
+ def upsert
16
+ if new?
17
+ insert
18
+ else
19
+ update
20
+ end
21
+ end
22
+
23
+ def upsert!
24
+ if new?
25
+ insert!
26
+ else
27
+ update!
28
+ end
29
+ end
30
+
30
31
  module ClassMethods
31
32
  def model_name
32
33
  @_model_name ||= ActiveModel::Name.new(self)
33
34
  end
34
35
  end
36
+
37
+ module Errors
38
+ def any?
39
+ !empty?
40
+ end
41
+
42
+ def count
43
+ @errors.values.inject(0) { |sum, errors| sum += errors.size }
44
+ end
45
+ end
35
46
  end
36
47
  end
37
48
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jordan West
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-17 00:00:00 -07:00
17
+ date: 2010-11-16 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,13 +23,13 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
30
- - 3
31
- - 1
32
- version: 0.3.1
30
+ - 6
31
+ - 0
32
+ version: 0.6.0
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  description: Mongomatic is a simple Ruby object mapper for Mongo
@@ -57,8 +57,8 @@ homepage: http://mongomatic.com/
57
57
  licenses: []
58
58
 
59
59
  post_install_message:
60
- rdoc_options:
61
- - --charset=UTF-8
60
+ rdoc_options: []
61
+
62
62
  require_paths:
63
63
  - lib
64
64
  required_ruby_version: !ruby/object:Gem::Requirement