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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcf3882c777f9cb8c824984d2eefaf5b4abdcc442439c2ab0bdcaa41a1c50177
4
- data.tar.gz: 2e2b31d76322c32bdb3c8147152151d94c7570653108f47a9d1486914335a3b8
3
+ metadata.gz: 5730dcce3f54aca15736e052c5a98a758d0d691b243e544f406de15c7d1cbbb4
4
+ data.tar.gz: 3814ee64675fe80d44e96a15ff17e05d849c71f44477c607a388a7c3f9863a53
5
5
  SHA512:
6
- metadata.gz: 168688c5ae6ccce8007d462b6b352a5ef237f403091b96159da32548a4e684b92b8222956140875aace4f1ad3629882e7b11f7967b592deececf54732985b3ea
7
- data.tar.gz: 055e466d0dd48a9cc002e0c294921096b2741ef5c77ef4f15202c08377eee5d32686be7e91522241631eb7688fa8dfe2f1cfdb6a4f310be8df0c9f3ed6b03f8e
6
+ metadata.gz: b6b884d39e9b34f8a13237413753fbfe5265e51f463a93befe6c4b848b8bce379f37cfb84103f425788042b6480a138f4a51e87fffb039d77a6ae01b5d8f9bcf
7
+ data.tar.gz: 751d69add77372aa90f657d4a6802f1794391f7155ff9451a019750704e6cf84c125212a9c97d41e5049ce9bed26e9e379ccf1d693ddce3797c37525321f4b6c
data/.gitignore CHANGED
@@ -7,6 +7,8 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  .idea
10
+ *.gem
11
+ .ruby-version
10
12
 
11
13
  # rspec failure tracking
12
14
  .rspec_status
data/README.md CHANGED
@@ -1,38 +1,58 @@
1
- # Emerald::Orm
1
+ # EmeraldODM
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/emerald/orm`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- Add this line to your application's Gemfile:
7
+ ## Installation
10
8
 
11
- ```ruby
12
- gem 'emerald-orm'
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
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/emerald-orm.
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/MikaelSantilio/emerald-odm.
36
56
 
37
57
 
38
58
  ## License
@@ -1,3 +1,3 @@
1
1
  module EmeraldODM
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.1'
3
3
  end
data/lib/emerald_odm.rb CHANGED
@@ -24,8 +24,7 @@ module EmeraldODM
24
24
  end
25
25
  end
26
26
 
27
- class Collection
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.0.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-18 00:00:00.000000000 Z
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.7
148
+ rubygems_version: 2.7.6
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: MongoDB ODM