mongoid-collection-separated 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
  SHA256:
3
- metadata.gz: 2db1c0e56ef0f51a62a9cae1301527cc601207cdc3d29c88d0b0b62ee4434056
4
- data.tar.gz: d483cfedb5024cfd7b1773309878fffb11273e17951f7a7a70f15eb3aed58e3e
3
+ metadata.gz: bfba70a37de67de41dc7d5d0adf80a2a2b3d5bc8e2c33ad8aa69b135e9b6f5f3
4
+ data.tar.gz: a44ba06116ad965932694728814144307946de2e3defe2718d4266cce185e3b4
5
5
  SHA512:
6
- metadata.gz: c2f90b4d09bf56814bf34c8918f943a219b84995daf2a4b21fab506d34850ee050c44f25caae72dd444d2d42290840e08bd11dfde16ec011021ebfa9de87dff7
7
- data.tar.gz: e848e4bfc8cf1858e17b1bf3b4d157a92fd090a8c7e0f4cf8a88ee57c58295769855b32d630b88d4e4b1e2c253b3d189d0abcc9e0cbdcffc183fa971c4974460
6
+ metadata.gz: cba3d857433998e06971c0493c0708986509ad5afd63ecb78c6c68347eef00537052f44fbbea291fe8b3b8aa9c7b9469f9cc1d9fd370b45e0b36e4508b9bba6c
7
+ data.tar.gz: '048c3cf68d0e75226afc477b70fbb9acf42ce2cd419e263c97201ac7fec5b498ab4a27b27e39907c7263a1a25dc536d2f1dfab53347ed667dcd9b1523f04cedd'
data/README.md CHANGED
@@ -20,13 +20,53 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
  Add the following line into the model class that you want to split:
23
+ ### 1. spepated by simple field
23
24
  ```ruby
24
- separated_by :form_id, :calc_collection_name
25
+ class Entry
26
+ include Mongoid::Document
27
+ include Mongoid::Timestamps
28
+ include Mongoid::CollectionSeparated
29
+ include Mongoid::Attributes::Dynamic
30
+
31
+ separated_by :collection_suffix, :calc_collection_name
32
+ class << self
33
+ def calc_collection_name collection_suffix
34
+ return if collection_suffix.nil?
35
+ "entries_#{collection_suffix}"
36
+ end
37
+ end
38
+ end
39
+ ```
40
+
41
+ ### 2. spepated by belongs to model id
42
+ ```ruby
43
+ class Entry
44
+ include Mongoid::Document
45
+ include Mongoid::Timestamps
46
+ include Mongoid::CollectionSeparated
47
+ include Mongoid::Attributes::Dynamic
48
+ belongs_to :form
49
+
50
+ separated_by :form_id, :calc_collection_name, parent_class: 'Form'
51
+ class << self
52
+ def calc_collection_name form_id
53
+ return if form_id.nil?
54
+ "entries_#{form_id}"
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ class Form
61
+ include Mongoid::Document
62
+ has_many :entries
63
+ end
64
+
25
65
  ```
26
66
 
27
67
  ## Contributing
28
68
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongoid_collection_separatable.
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/WeiGangqiang/mongoid_collection_separated
30
70
 
31
71
  ## License
32
72
 
@@ -20,8 +20,8 @@ module Mongoid
20
20
 
21
21
  def calc_new_collection_name query_class
22
22
  return unless query_class.respond_to?(:separated_field) && query_class.send(:separated_field).present?
23
- return unless query_class.respond_to?(:calc_collection_name_fun) || query_class.respond_to?(query_class.calc_collection_name_fun)
24
- query_class.send(query_class.calc_collection_name_fun, (separated_value(query_class)))
23
+ return unless query_class.respond_to?(:calc_collection_name_fun) && query_class.respond_to?(query_class.calc_collection_name_fun)
24
+ query_class.send(query_class.calc_collection_name_fun, separated_value(query_class))
25
25
  end
26
26
 
27
27
  def separated_value query_class
@@ -68,11 +68,18 @@ module Mongoid
68
68
  end
69
69
 
70
70
  def should_query_from_separated_collection?(query_class)
71
- query_class.respond_to?(:separated_field) && query_class.send(:separated_field) && base.is_a?(query_class.separated_parent_class) && base.respond_to?(query_class.separated_parent_field)
71
+ is_separated_query_class?(query_class) && is_separated_parent_class?(query_class)
72
+ end
73
+
74
+ def is_separated_query_class? query_class
75
+ query_class.respond_to?(:separated_field) && query_class.send(:separated_field) && query_class.respond_to?(:calc_collection_name_fun) && query_class.respond_to?(query_class.calc_collection_name_fun)
76
+ end
77
+
78
+ def is_separated_parent_class? query_class
79
+ base.is_a?(query_class.separated_parent_class) && base.respond_to?(query_class.separated_parent_field)
72
80
  end
73
81
 
74
82
  def calc_new_collection_name query_class
75
- return unless query_class.respond_to?(:calc_collection_name_fun) or query_class.respond_to?(query_class.calc_collection_name_fun)
76
83
  query_class.send(query_class.calc_collection_name_fun, base.send(query_class.separated_parent_field))
77
84
  end
78
85
 
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  module CollectionSeparated
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-collection-separated
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
  - aibotyu