mongoid-denormalization 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: aa1a0ba39056d1e83f3f6b9979d7a35ab94b5385
4
- data.tar.gz: ebb5f7a673846691c0125e2688dabe112441b513
3
+ metadata.gz: 70d9924038cb24d4c90d1a759f1a5f6a1ad5ce38
4
+ data.tar.gz: 37f730557a69d668d26763e991136d2469a69d94
5
5
  SHA512:
6
- metadata.gz: 4ab451d3b02ca0be0085802d4760e052a1e1dcbcbb14edcd0020ce2d217e97b52e78bd7b238c45b9bc98cdafabf466e72bc8d3f0f9c872a253f96c20c6f1c509
7
- data.tar.gz: d23b0d4a2913d3a5bfca789954f76a5d5098dbae7f1d8e8f8de455b1cb5c4ad56ef4c6ef8a756425264495f8127cd225f83bd2944ff9c1d864501d7b965704c6
6
+ metadata.gz: dad19e9a0236597a5b33d28d344f7af9c052987e187db742e853ca2fb4643b3405325470bf6126f42a1bee4dfdc2a6f2081711993d4526eeadf5af24a2e7ddd5
7
+ data.tar.gz: 6cf60d715b07b80892fb97851abf5376ba46dec638732bb9abd1b69b928b6f4d00330e82d5ce099b9c6d53a4b743e4dc9d5dbecfa368d490713fc4a2d5673d4e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-denormalization (0.1.1)
4
+ mongoid-denormalization (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Mongoid::Denormalization
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/mongoid/denormalization`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Helper module for denormalizing association attributes in Mongoid models & embedded models.
4
+ Supports rails 5.1.4, mongoid 6.2, ruby 2.4.2
6
5
 
7
6
  ## Installation
8
7
 
@@ -14,7 +13,7 @@ gem 'mongoid-denormalization'
14
13
 
15
14
  And then execute:
16
15
 
17
- $ bundle
16
+ $ bundle install
18
17
 
19
18
  Or install it yourself as:
20
19
 
@@ -22,7 +21,55 @@ Or install it yourself as:
22
21
 
23
22
  ## Usage
24
23
 
25
- TODO: Write usage instructions here
24
+ In your model:
25
+ ```ruby
26
+ # Include the helper method
27
+ include Mongoid::Denormalization
28
+
29
+ # Define your denormalization
30
+ denormalize_from(:user, :name) # this will add a user_name field on your model
31
+ denormalize_from(:user, :email) # this will add a user_email field on your model
32
+ ```
33
+
34
+ Optionally, you can also write it as
35
+ ```ruby
36
+ # this will add a username field on your model
37
+ denormalize_from(:user, :name, :denormalized_field_name => :username)
38
+
39
+ # this will add a useremail field on your model
40
+ denormalize_from(:user, :email, :denormalized_field_name => :useremail)
41
+ ```
42
+
43
+ Lets say we have a company model with embedded jobs in it. We want to denormalize user_name and user_email in jobs.
44
+ We can write the following code in our jobs model:
45
+
46
+ ```ruby
47
+ denormalize_from(:user, :name, to_klass_infos: [{
48
+ klasses: [::Company],
49
+ selector_proc: Proc.new do |id, value|
50
+ {:jobs => {"$elemMatch" => {:user_id => id, :user_name => {"$ne" => value}}}}
51
+ end,
52
+ updator: "jobs.$.user_name",
53
+ index_key: "jobs.user_id"
54
+ }])
55
+
56
+ denormalize_from(:user, :email, to_klass_infos: [{
57
+ klasses: [::Company],
58
+ selector_proc: Proc.new do |id, value|
59
+ {:jobs => {"$elemMatch" => {:user_id => id, :user_email => {"$ne" => value}}}}
60
+ end,
61
+ updator: "jobs.$.user_email",
62
+ index_key: "jobs.user_id"
63
+ }])
64
+ ```
65
+
66
+ You can call force_denormalize also,
67
+ ```ruby
68
+ company.force_denormalize # this will simply sync all the denormalized fields and will not triiger a save on document.
69
+ company.force_denormalize! # this will sync all the denormalized fields and will also triiger a save on document.
70
+ ```
71
+
72
+ Note: you should also create proper db indexes required, otherwise the module may through an error.
26
73
 
27
74
  ## Development
28
75
 
@@ -32,7 +79,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
79
 
33
80
  ## Contributing
34
81
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongoid-denormalization. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chaudhary/mongoid-denormalization. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
83
 
37
84
  ## License
38
85
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Denormalization
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-denormalization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amit Chaudhary