mongo_db 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- module Mongo::Ext::ModelHelper
1
+ module Mongo::Ext::ObjectHelper
2
2
  #
3
3
  # CRUD
4
4
  #
@@ -21,7 +21,7 @@ module Mongo::Ext::ModelHelper
21
21
  end
22
22
 
23
23
  def update_with_model selector, doc, opts = {}
24
- doc = Mongo::Ext::ModelHelper.convert_object_to_doc doc unless doc.is_a?(Hash)
24
+ doc = Mongo::Ext::ObjectHelper.convert_object_to_doc doc unless doc.is_a?(Hash)
25
25
  update_without_model selector, doc, opts
26
26
  end
27
27
 
@@ -40,12 +40,12 @@ module Mongo::Ext::ModelHelper
40
40
  #
41
41
  def first *args, &block
42
42
  doc = super *args, &block
43
- Mongo::Ext::ModelHelper.convert_doc_to_object doc
43
+ Mongo::Ext::ObjectHelper.convert_doc_to_object doc
44
44
  end
45
45
 
46
46
  def each *args, &block
47
47
  super *args do |doc|
48
- doc = Mongo::Ext::ModelHelper.convert_doc_to_object(doc)
48
+ doc = Mongo::Ext::ObjectHelper.convert_doc_to_object(doc)
49
49
  block.call doc
50
50
  end
51
51
  nil
@@ -54,11 +54,11 @@ module Mongo::Ext::ModelHelper
54
54
  protected
55
55
  def _insert_with_model docs, opts
56
56
  hashes = docs.collect do |doc|
57
- doc.is_a?(Hash) ? doc : Mongo::Ext::ModelHelper.convert_object_to_doc(doc)
57
+ doc.is_a?(Hash) ? doc : Mongo::Ext::ObjectHelper.convert_object_to_doc(doc)
58
58
  end
59
59
  result = insert_without_model hashes, opts
60
60
  hashes.each_with_index do |h, i|
61
- Mongo::Ext::ModelHelper.update_object_after_insertion docs[i], h
61
+ Mongo::Ext::ObjectHelper.update_object_after_insertion docs[i], h
62
62
  end
63
63
  result
64
64
  end
@@ -1,13 +1,12 @@
1
1
  require 'mongo_db/driver'
2
2
 
3
3
  %w(
4
- model_serializer
5
- model_helper
6
- ).each{|f| require "mongo_db/model/#{f}"}
4
+ object_helper
5
+ ).each{|f| require "mongo_db/object/#{f}"}
7
6
 
8
7
  # collection
9
8
  Mongo::Collection.class_eval do
10
- include Mongo::Ext::ModelHelper
9
+ include Mongo::Ext::ObjectHelper
11
10
 
12
11
  %w(insert update remove save).each do |method|
13
12
  alias_method "#{method}_without_model", method
data/readme.md CHANGED
@@ -1,17 +1,19 @@
1
1
  Object Model & Ruby driver enhancements for MongoDB.
2
2
 
3
- - Driver enchancements
4
- - Persistence for pure Ruby objects
5
- - Migrations (work in progress)
6
- - Object Model (callbacks, validations, mass-assignment, finders, ...) (work in progress)
3
+ 1. Driver enchancements
4
+ 2. Persistence for pure Ruby objects
5
+ 3. Object Model (callbacks, validations, mass-assignment, finders, ...) (work in progress)
6
+
7
+ Lower layers are completely independent from upper, use only what You need. There are also support for migrations.
7
8
 
8
9
  # MongoDB driver enhancements
9
10
 
10
- MongoDB itself is very powerful, flexible and simple tool, but it's Ruby driver has a little complicated API.
11
- This enhancements alter this API to be more simple and intuitive.
11
+ MongoDB itself is very powerful, flexible and simple tool, but the API of the Ruby driver is a little complicated.
12
+ These enhancements alter the driver's API and made it more simple and intuitive.
12
13
 
13
14
  - Makes API of mongo-ruby-driver friendly & handy.
14
15
  - No extra abstraction or complexities introduced, all things are exactly the same as in MongoDB.
16
+ - 100% backward compatibility with original driver API (if not - it's a bug, report it please)
15
17
 
16
18
  ``` ruby
17
19
  require 'mongo_db/driver/core'
@@ -42,9 +44,7 @@ db.units.all name: 'Zeratul' do |unit|
42
44
  end
43
45
  ```
44
46
 
45
- Optionall stuff:
46
-
47
- - Simple query enchancements
47
+ Optionall stuff - simple query enchancements:
48
48
 
49
49
  ``` ruby
50
50
  require 'mongo_db/driver/more'
@@ -59,12 +59,12 @@ Mongo.defaults.merge! convert_underscore_to_dollar: true
59
59
  db.units.all 'stats.life' => {_lt: 100} # => [tassadar]
60
60
  ```
61
61
 
62
- More docs - there's no need for more docs, the whole point of this extension is to be small, intuitive, 100% compatible with the official driver (at least should be), and require no extra knowledge.
62
+ More docs - there's no need for more docs, the whole point of this extension is to be small, intuitive, 100% compatible with the official driver, and require no extra knowledge.
63
63
  So, please use standard Ruby driver documentation.
64
64
 
65
65
  # Persistence for pure Ruby objects
66
66
 
67
- Save any Ruby object to MongoDB, as if it's hash. Object can be any type, simple or composite with other objects / arrays / hashes inside.
67
+ Save any Ruby object to MongoDB, as if it's a document. Objects can be any type, simple or composite with other objects / arrays / hashes inside.
68
68
 
69
69
  Note: the :initialize method should allow to create object without arguments.
70
70
 
@@ -88,7 +88,7 @@ class Unit
88
88
  end
89
89
 
90
90
  # connecting to MongoDB
91
- require 'mongo_db/model'
91
+ require 'mongo_db/object'
92
92
  Mongo.defaults.merge! symbolize: true, multi: true, safe: true
93
93
  connection = Mongo::Connection.new
94
94
  db = connection.db 'default_test'
@@ -134,20 +134,12 @@ Model designed after the excellent "Domain-Driven Design" book by Eric Evans.
134
134
  - Full support for embedded objects (and MDD composite pattern).
135
135
  - Doesn't try to mimic ActiveRecord, it's differrent and designed to get most of MongoDB.
136
136
 
137
- # Installation & Usage
138
-
139
- Installation:
137
+ # Installation
140
138
 
141
139
  ``` bash
142
140
  gem install mongo_db
143
141
  ```
144
142
 
145
- Usage:
146
-
147
- ``` ruby
148
- require 'mongo_db/driver'
149
- ```
150
-
151
143
  # License
152
144
 
153
145
  Copyright (c) Alexey Petrushin, http://petrush.in, released under the MIT license.
File without changes
@@ -1,4 +1,4 @@
1
- require 'mongo_db/model'
1
+ require 'mongo_db/object'
2
2
  require 'rspec'
3
3
 
4
4
  describe "Object example" do
@@ -29,7 +29,7 @@ describe "Object example" do
29
29
  end
30
30
 
31
31
  # connecting to MongoDB
32
- require 'mongo_db/model'
32
+ require 'mongo_db/object'
33
33
  Mongo.defaults.merge! symbolize: true, multi: true, safe: true
34
34
  connection = Mongo::Connection.new
35
35
  db = connection.db 'default_test'
@@ -1,3 +1,3 @@
1
- require 'mongo_db/model'
1
+ require 'mongo_db/object'
2
2
 
3
3
  require 'driver/spec_helper'
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo
16
- requirement: &2844710 !ruby/object:Gem::Requirement
16
+ requirement: &2844750 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2844710
24
+ version_requirements: *2844750
25
25
  description:
26
26
  email:
27
27
  executables: []
@@ -38,10 +38,8 @@ files:
38
38
  - lib/mongo_db/driver/spec.rb
39
39
  - lib/mongo_db/driver.rb
40
40
  - lib/mongo_db/gems.rb
41
- - lib/mongo_db/model/model_helper.rb
42
- - lib/mongo_db/model/model_serializer.rb
43
- - lib/mongo_db/model.rb
44
- - lib/mongo_db/support.rb
41
+ - lib/mongo_db/object/object_helper.rb
42
+ - lib/mongo_db/object.rb
45
43
  - spec/driver/core/collection_spec.rb
46
44
  - spec/driver/core/crud_spec.rb
47
45
  - spec/driver/core/database_spec.rb
@@ -54,11 +52,12 @@ files:
54
52
  - spec/model/callbacks.rb
55
53
  - spec/model/example.rb
56
54
  - spec/model/model_crud.rb
57
- - spec/model/validation.rb
55
+ - spec/object/callbacks.rb
58
56
  - spec/object/crud_shared.rb
59
57
  - spec/object/example_spec.rb
60
58
  - spec/object/object_crud_spec.rb
61
59
  - spec/object/spec_helper.rb
60
+ - spec/object/validation.rb
62
61
  - spec/test.rb
63
62
  homepage: http://github.com/alexeypetrushin/mongo_db
64
63
  licenses: []
@@ -1,3 +0,0 @@
1
- class Mongo::Ext::ModelSerializer
2
-
3
- end
@@ -1,30 +0,0 @@
1
-
2
-
3
- # Hash.class_eval do
4
- # unless defined_method? :subset
5
- # def subset *keys, &block
6
- # keys = keys.first if keys.first.is_a? Array
7
- # h = {}
8
- # if keys
9
- # self.each do |k, v|
10
- # h[k] = v if keys.include? k
11
- # end
12
- # else
13
- # self.each do |k, v|
14
- # h[k] = v if block.call k
15
- # end
16
- # end
17
- # h
18
- # end
19
- # end
20
- #
21
- # unless defined_method? :reverse_merge
22
- # def reverse_merge(other_hash)
23
- # other_hash.merge(self)
24
- # end
25
- #
26
- # def reverse_merge!(other_hash)
27
- # merge!(other_hash){|k,o,n| o }
28
- # end
29
- # end
30
- # end