mongoid-collection-separated 0.2.2 → 0.3.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c93b8ba4b2578a02d4c742f7f32da37e987a193b432c46a0940d58e25436852a
|
4
|
+
data.tar.gz: b8e532c66fde7ad1a94e4a24039d666bd130727ceb48c01f1e831219c5e537e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7f7b633a8c184b940f97fd87a70e9c03cf309a3d302360c42822fd148f37f5b97eb84d1d93675eef5ce3b975f97b172929912f83c12ef655c3cd306dad1de32
|
7
|
+
data.tar.gz: cdfef2d83d9f94c0bd1930ffdcc49f0fe0e8cf685738aeb40e87cf00854e014ea174be327d2a0f24bbc1f2d38ebe2dafa6177d3c5a41d14b6bd5ecfffcdef28c
|
data/Gemfile.lock
CHANGED
@@ -10,12 +10,20 @@ module Mongoid
|
|
10
10
|
|
11
11
|
class_methods do
|
12
12
|
attr_accessor :separated_field, :separated_parent_class, :separated_parent_field, :calc_collection_name_fun
|
13
|
+
|
13
14
|
def separated_by separated_field, calc_collection_name_fun, opts={}
|
14
15
|
@separated_parent_class = opts[:parent_class].constantize
|
15
16
|
@separated_parent_field = opts[:parent_field] || :id
|
16
17
|
@separated_field = separated_field
|
17
18
|
@calc_collection_name_fun = calc_collection_name_fun
|
18
19
|
end
|
20
|
+
|
21
|
+
def ensure_collection_name separate_key
|
22
|
+
cache_key = "#{__method__}_#{separate_key}"
|
23
|
+
return instance_variable_get "@#{cache_key}" if instance_variable_defined? "@#{cache_key}"
|
24
|
+
collection_name = self.send(self.send(:calc_collection_name_fun), separate_key)
|
25
|
+
instance_variable_set "@#{cache_key}", collection_name
|
26
|
+
end
|
19
27
|
end
|
20
28
|
|
21
29
|
end
|
@@ -21,7 +21,7 @@ module Mongoid
|
|
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
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(
|
24
|
+
query_class.send(:ensure_collection_name, separated_value(query_class))
|
25
25
|
end
|
26
26
|
|
27
27
|
def separated_value query_class
|
@@ -80,7 +80,7 @@ module Mongoid
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def calc_new_collection_name query_class
|
83
|
-
query_class.send(
|
83
|
+
query_class.send(:ensure_collection_name, base.send(query_class.separated_parent_field))
|
84
84
|
end
|
85
85
|
|
86
86
|
alias_method :criteria_without_separated, :criteria
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-collection-separated
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aibotyu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -120,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.7.8
|
123
|
+
rubygems_version: 3.0.1
|
125
124
|
signing_key:
|
126
125
|
specification_version: 4
|
127
126
|
summary: Save the mongoid model into different collections by condition
|