emerald_odm 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +43 -23
- data/lib/emerald_odm/version.rb +1 -1
- data/lib/emerald_odm.rb +18 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5730dcce3f54aca15736e052c5a98a758d0d691b243e544f406de15c7d1cbbb4
|
4
|
+
data.tar.gz: 3814ee64675fe80d44e96a15ff17e05d849c71f44477c607a388a7c3f9863a53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6b884d39e9b34f8a13237413753fbfe5265e51f463a93befe6c4b848b8bce379f37cfb84103f425788042b6480a138f4a51e87fffb039d77a6ae01b5d8f9bcf
|
7
|
+
data.tar.gz: 751d69add77372aa90f657d4a6802f1794391f7155ff9451a019750704e6cf84c125212a9c97d41e5049ce9bed26e9e379ccf1d693ddce3797c37525321f4b6c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,58 @@
|
|
1
|
-
#
|
1
|
+
# EmeraldODM
|
2
2
|
|
3
|
-
|
3
|
+
EmeraldODM is an simple ODM (Object-Document Mapper) framework for MongoDB in Ruby.
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
5
|
|
7
|
-
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
## Installation
|
10
8
|
|
11
|
-
```
|
12
|
-
gem
|
9
|
+
```bash
|
10
|
+
gem install emerald_odm
|
13
11
|
```
|
14
12
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install emerald-orm
|
22
|
-
|
23
13
|
## Usage
|
24
14
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
15
|
+
```ruby
|
16
|
+
require 'emerald_odm'
|
17
|
+
|
18
|
+
# 1. Setup DB connection
|
19
|
+
EmeraldODM.databases_settings.merge!(
|
20
|
+
{
|
21
|
+
test: [
|
22
|
+
[ ENV['IP_MONGO_DATABASE'] ],
|
23
|
+
{
|
24
|
+
database: 'test',
|
25
|
+
user: ENV['DB_LOGIN'],
|
26
|
+
password: ENV['DB_PASSWD'],
|
27
|
+
auth_source: ENV['auth_source'],
|
28
|
+
max_pool_size: 20,
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
)
|
33
|
+
|
34
|
+
# 2. Define your model
|
35
|
+
class Users < EmeraldODM::Collection
|
36
|
+
attr_accessor :_id, :name, :email, :age
|
37
|
+
|
38
|
+
def self.collection_name
|
39
|
+
:users
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.db_name
|
43
|
+
:test
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# 3. Use it
|
48
|
+
Users.find(filter: {_id: '5c9b9b9b9b9b9b9b9b9b9b9b'}).first
|
49
|
+
|
50
|
+
Users.update_one(filter: {_id: '5c9b9b9b9b9b9b9b9b9b9b9b'}, set: {name: 'John Doe'}, unset: {age: 1})
|
51
|
+
```
|
32
52
|
|
33
53
|
## Contributing
|
34
54
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/MikaelSantilio/emerald-odm.
|
36
56
|
|
37
57
|
|
38
58
|
## License
|
data/lib/emerald_odm/version.rb
CHANGED
data/lib/emerald_odm.rb
CHANGED
@@ -24,8 +24,7 @@ module EmeraldODM
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
class
|
28
|
-
|
27
|
+
class AttrInitializer
|
29
28
|
attr_reader :document
|
30
29
|
|
31
30
|
def initialize(document)
|
@@ -36,14 +35,6 @@ module EmeraldODM
|
|
36
35
|
instance_variable_set('@document', document)
|
37
36
|
end
|
38
37
|
|
39
|
-
# @return [Symbol, nil]
|
40
|
-
def self.db_name
|
41
|
-
nil
|
42
|
-
end
|
43
|
-
# @return [Symbol, nil]
|
44
|
-
def self.collection_name
|
45
|
-
nil
|
46
|
-
end
|
47
38
|
# @return [Array]
|
48
39
|
def self.fields
|
49
40
|
public_instance_methods = self.public_instance_methods(false).grep(/=$/)
|
@@ -57,6 +48,23 @@ module EmeraldODM
|
|
57
48
|
fields
|
58
49
|
end
|
59
50
|
|
51
|
+
def nil?
|
52
|
+
document.nil? || document.empty?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Collection < AttrInitializer
|
57
|
+
|
58
|
+
# @return [Symbol, nil]
|
59
|
+
def self.db_name
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Symbol, nil]
|
64
|
+
def self.collection_name
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
60
68
|
# @return [Mongo::Collection] The collection
|
61
69
|
def self.collection
|
62
70
|
Connector.database(db_name&.to_sym)[collection_name&.to_sym]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emerald_odm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mikael
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.7.
|
148
|
+
rubygems_version: 2.7.6
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: MongoDB ODM
|