mongoid-collection-separated 0.2.2 → 0.3.0

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: bbcfb28aa8720aca9c5cd1d2a1cd367edddf58be667c38c8c6339f3394f7bf31
4
- data.tar.gz: 9b8e39fe7734198249b60e3c87d6eb8926b799d1b73f1fd785d3f1c18a1478d4
3
+ metadata.gz: c93b8ba4b2578a02d4c742f7f32da37e987a193b432c46a0940d58e25436852a
4
+ data.tar.gz: b8e532c66fde7ad1a94e4a24039d666bd130727ceb48c01f1e831219c5e537e1
5
5
  SHA512:
6
- metadata.gz: 0f092742e2e26f1227d38e8a1d69a48bfdfde543da5e0081f167528bdd700747233aafe7d28b7274fad6f2830030e4cc249ce60740ecf66d49810f39ea63a08a
7
- data.tar.gz: 135fe9df6a833390a2fb14d0c6e1f10d21f75e107f320a0bef156e8bd8fecab51f15a68be64e56d4c1e705ff868fa7edc730b4196e0aa5673a900b7a5ca65b24
6
+ metadata.gz: f7f7b633a8c184b940f97fd87a70e9c03cf309a3d302360c42822fd148f37f5b97eb84d1d93675eef5ce3b975f97b172929912f83c12ef655c3cd306dad1de32
7
+ data.tar.gz: cdfef2d83d9f94c0bd1930ffdcc49f0fe0e8cf685738aeb40e87cf00854e014ea174be327d2a0f24bbc1f2d38ebe2dafa6177d3c5a41d14b6bd5ecfffcdef28c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-collection-separated (0.2.0)
4
+ mongoid-collection-separated (0.3.0)
5
5
  mongoid (~> 6.2)
6
6
 
7
7
  GEM
@@ -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(query_class.calc_collection_name_fun, separated_value(query_class))
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(query_class.calc_collection_name_fun, base.send(query_class.separated_parent_field))
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
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  module CollectionSeparated
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
6
6
 
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.2.2
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-03-18 00:00:00.000000000 Z
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
- rubyforge_project:
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