mongomodel 0.5.4 → 0.5.5
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -13
- data/README.md +33 -8
- data/lib/mongomodel.rb +7 -1
- data/lib/mongomodel/support/configuration.rb +40 -34
- data/lib/mongomodel/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ecf9f958c03a225872acdf72dca43ff7d6fc52d
|
4
|
+
data.tar.gz: fcca66094d1b48857a28792c12364d49ae057593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6a69c5fddc9745f8db566ad2931ee0f5069e8047f0ca834eb08c3bb6ac8d1f4201f21ca3f3f5de0267efc86a054330a2586d23adb0a63dbf01b8ed8bf60424f
|
7
|
+
data.tar.gz: bfefd11ce4643a8990c315aba9faa422cedbc026b1179e6cc7d4e2c4b69682139b1cb58ba0dd025ec38bf52bcc6d1cc7d043b3164483ae3a903cc17582d35885
|
data/.travis.yml
CHANGED
@@ -4,7 +4,6 @@ services:
|
|
4
4
|
- mongodb
|
5
5
|
|
6
6
|
rvm:
|
7
|
-
- 1.8.7
|
8
7
|
- 1.9.3
|
9
8
|
- 2.0.0
|
10
9
|
- 2.1.0
|
@@ -17,15 +16,3 @@ gemfile:
|
|
17
16
|
- gemfiles/rails-4-observers.gemfile
|
18
17
|
- gemfiles/mongo_mapper.gemfile
|
19
18
|
- gemfiles/mongoid.gemfile
|
20
|
-
|
21
|
-
matrix:
|
22
|
-
exclude:
|
23
|
-
- rvm: 1.8.7
|
24
|
-
gemfile: gemfiles/rails-4.0.gemfile
|
25
|
-
- rvm: 1.8.7
|
26
|
-
gemfile: gemfiles/rails-4.1.gemfile
|
27
|
-
- rvm: 1.8.7
|
28
|
-
gemfile: gemfiles/rails-4-observers.gemfile
|
29
|
-
- rvm: 1.8.7
|
30
|
-
gemfile: gemfiles/mongoid.gemfile
|
31
|
-
|
data/README.md
CHANGED
@@ -18,8 +18,8 @@ For performance, you should probably also install the BSON C extensions:
|
|
18
18
|
gem install bson_ext
|
19
19
|
|
20
20
|
|
21
|
-
Using with Rails
|
22
|
-
|
21
|
+
Using with Rails
|
22
|
+
================
|
23
23
|
|
24
24
|
Add MongoModel to your Gemfile (and run `bundle install`):
|
25
25
|
|
@@ -38,13 +38,9 @@ Generating an embedded document:
|
|
38
38
|
rails generate model Chapter title:string body:string -E
|
39
39
|
|
40
40
|
|
41
|
-
Sample
|
41
|
+
Sample Model
|
42
42
|
============
|
43
43
|
|
44
|
-
require 'mongomodel'
|
45
|
-
|
46
|
-
MongoModel.configuration = { 'host' => 'localhost', 'database' => 'mydb' }
|
47
|
-
|
48
44
|
class Article < MongoModel::Document
|
49
45
|
property :title, String, :default => 'Untitled'
|
50
46
|
property :body, String
|
@@ -59,4 +55,33 @@ Sample Usage
|
|
59
55
|
|
60
56
|
scope :published, where(:published_at.ne => nil)
|
61
57
|
end
|
62
|
-
|
58
|
+
|
59
|
+
|
60
|
+
Configuration
|
61
|
+
=============
|
62
|
+
|
63
|
+
MongoModel can be configured similarly to ActiveRecord by creating/editing `config/mongomodel.yml`. The most basic configuration might look like:
|
64
|
+
|
65
|
+
```yaml
|
66
|
+
development:
|
67
|
+
database: mymongodbname
|
68
|
+
host: localhost
|
69
|
+
port: 27017
|
70
|
+
```
|
71
|
+
|
72
|
+
The config file also supports specifying the username, password, pool_size, password and replicas. Running `rails generate mongo_model:config DATABASENAME` will generate a basic config file for you.
|
73
|
+
|
74
|
+
Using Replica Sets
|
75
|
+
------------------
|
76
|
+
|
77
|
+
When working with replica sets, replace the host/port configuration with an array of replicas (`host:port`):
|
78
|
+
|
79
|
+
```yaml
|
80
|
+
production:
|
81
|
+
database: database_name
|
82
|
+
replicas:
|
83
|
+
- some.host.com:27017
|
84
|
+
- another.host.com:27017
|
85
|
+
username: username
|
86
|
+
password: password
|
87
|
+
```
|
data/lib/mongomodel.rb
CHANGED
@@ -49,6 +49,7 @@ module MongoModel
|
|
49
49
|
autoload :Scope, 'mongomodel/support/scope'
|
50
50
|
autoload :Types, 'mongomodel/support/types'
|
51
51
|
autoload :Configuration, 'mongomodel/support/configuration'
|
52
|
+
autoload :URIConfiguration, 'mongomodel/support/configuration'
|
52
53
|
autoload :DynamicFinder, 'mongomodel/support/dynamic_finder'
|
53
54
|
autoload :InstrumentedCollection, 'mongomodel/support/instrumented_collection'
|
54
55
|
|
@@ -104,7 +105,12 @@ module MongoModel
|
|
104
105
|
|
105
106
|
def self.configuration=(config)
|
106
107
|
@_database = nil
|
107
|
-
@_configuration =
|
108
|
+
@_configuration = case config
|
109
|
+
when Hash
|
110
|
+
Configuration.new(config)
|
111
|
+
when String
|
112
|
+
URIConfiguration.new(config)
|
113
|
+
end
|
108
114
|
end
|
109
115
|
|
110
116
|
def self.database
|
@@ -3,8 +3,18 @@ require 'active_support/core_ext/hash/except'
|
|
3
3
|
|
4
4
|
module MongoModel
|
5
5
|
class Configuration
|
6
|
+
DEFAULTS = {
|
7
|
+
'host' => 'localhost',
|
8
|
+
'port' => 27017,
|
9
|
+
'database' => 'mongomodel-default',
|
10
|
+
'pool_size' => 5,
|
11
|
+
'pool_timeout' => 5
|
12
|
+
}
|
13
|
+
|
14
|
+
attr_reader :options
|
15
|
+
|
6
16
|
def initialize(options)
|
7
|
-
|
17
|
+
@options = DEFAULTS.merge(options).stringify_keys
|
8
18
|
end
|
9
19
|
|
10
20
|
def host
|
@@ -54,42 +64,38 @@ module MongoModel
|
|
54
64
|
options.except('host', 'port', 'database', 'username', 'password', 'replicas').symbolize_keys
|
55
65
|
end
|
56
66
|
|
57
|
-
def options
|
58
|
-
@options ||= {}
|
59
|
-
end
|
60
|
-
|
61
|
-
def set_options!(options)
|
62
|
-
case options
|
63
|
-
when Hash
|
64
|
-
@options = DEFAULTS.merge(options).stringify_keys
|
65
|
-
when String
|
66
|
-
set_options!(parse(options))
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
DEFAULTS = {
|
71
|
-
'host' => 'localhost',
|
72
|
-
'port' => 27017,
|
73
|
-
'database' => 'mongomodel-default',
|
74
|
-
'pool_size' => 5,
|
75
|
-
'pool_timeout' => 5
|
76
|
-
}
|
77
|
-
|
78
67
|
def self.defaults
|
79
68
|
new({})
|
80
69
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
70
|
+
end
|
71
|
+
|
72
|
+
class URIConfiguration
|
73
|
+
def initialize(uri)
|
74
|
+
@uri = uri
|
75
|
+
end
|
76
|
+
|
77
|
+
def host
|
78
|
+
parser.host
|
79
|
+
end
|
80
|
+
|
81
|
+
def port
|
82
|
+
parser.port
|
83
|
+
end
|
84
|
+
|
85
|
+
def database
|
86
|
+
parser.connection_options[:db_name]
|
87
|
+
end
|
88
|
+
|
89
|
+
def establish_connection
|
90
|
+
@database = connection.db
|
91
|
+
end
|
92
|
+
|
93
|
+
def connection
|
94
|
+
@connection ||= parser.connection({})
|
95
|
+
end
|
96
|
+
|
97
|
+
def parser
|
98
|
+
@parser ||= Mongo::URIParser.new(@uri)
|
93
99
|
end
|
94
100
|
end
|
95
101
|
end
|
data/lib/mongomodel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongomodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Pohlenz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -301,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
301
301
|
version: 1.3.6
|
302
302
|
requirements: []
|
303
303
|
rubyforge_project: mongomodel
|
304
|
-
rubygems_version: 2.
|
304
|
+
rubygems_version: 2.4.7
|
305
305
|
signing_key:
|
306
306
|
specification_version: 4
|
307
307
|
summary: MongoDB ORM for Ruby/Rails
|