acts-as-taggable-on-mongoid 6.1.1.7 → 6.1.1.12

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: a3389918de3bd83bfcc3ac3f82d9413d5a0f8ec076b8ae83c226d0787dd96158
4
- data.tar.gz: a2e731e6cf8b57d91697d3feb0fc61acca0073bbda5ef41452768bb42ffb7f57
3
+ metadata.gz: 36fd05cd0515afe5ba5a4012a9d005a00e9f371b67cd197dca5b5f744dd9bec0
4
+ data.tar.gz: 8fbc55a3df382f5af8291c3569e97554904e299f8bce503e177811ef6f412121
5
5
  SHA512:
6
- metadata.gz: 0a21b7c8cb425ce8a839411cf2bd5db8985bacf7d16b527c0f5fcc58431af787603928aa14a4c5ae9dd200836756188242b908173b69293067c4b3db1906aef4
7
- data.tar.gz: 67918b704a7b3cdeb1c200e883e806b12562e7724daa1f67a8ebeee2ce3452339e9b84c7de5916b9715193b6496be82b802598b073f35ce8d3ef4ba0d6981d24
6
+ metadata.gz: 598a21d16910f89bdb771329190bdbffa312ac6eb1be6b2db25ab586416dda0b8181403057e2a2dfe4d1b915ea6120656d17246cd4452f1bab5083dba851d77b
7
+ data.tar.gz: 70c7eb405020285ad773559a98e7c76fcab959e0e69f8083afce43041d2d72d71a00f572a62ef7f595ed371d6f81f75da47d1e4e44e820024232541cfac8a83b
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  require: rubocop-performance
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.3
4
+ TargetRubyVersion: 2.7.1
5
5
  Exclude:
6
6
  - 'vendor/**/*'
7
7
  - 'db/schema.rb'
@@ -13,6 +13,15 @@ AllCops:
13
13
  - 'node_modules/**/*'
14
14
  UseCache: false
15
15
 
16
+ Style/HashEachMethods:
17
+ Enabled: true
18
+
19
+ Style/HashTransformKeys:
20
+ Enabled: true
21
+
22
+ Style/HashTransformValues:
23
+ Enabled: true
24
+
16
25
  Style/CollectionMethods:
17
26
  Description: Preferred collection methods.
18
27
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
@@ -400,3 +409,15 @@ Layout/HashAlignment:
400
409
  - always_ignore
401
410
  - ignore_implicit
402
411
  - ignore_explicit
412
+
413
+ Layout/SpaceAroundMethodCallOperator:
414
+ Enabled: true
415
+
416
+ Lint/RaiseException:
417
+ Enabled: true
418
+
419
+ Lint/StructNewOverride:
420
+ Enabled: true
421
+
422
+ Style/ExponentialNotation:
423
+ Enabled: true
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.3
1
+ 2.7.1
data/Gemfile.lock CHANGED
@@ -1,187 +1,187 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acts-as-taggable-on-mongoid (6.1.1.7)
4
+ acts-as-taggable-on-mongoid (6.1.1.12)
5
5
  activesupport (>= 5.0)
6
- mongoid (>= 6.1.1, <= 7.0.2)
6
+ mongoid (>= 6.1.1, < 8.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.0.0)
12
- activesupport (= 5.0.0)
13
- activesupport (5.0.0)
11
+ activemodel (5.2.6)
12
+ activesupport (= 5.2.6)
13
+ activesupport (5.2.6)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (~> 0.7)
15
+ i18n (>= 0.7, < 2)
16
16
  minitest (~> 5.1)
17
17
  tzinfo (~> 1.1)
18
- addressable (2.7.0)
18
+ addressable (2.8.0)
19
19
  public_suffix (>= 2.0.2, < 5.0)
20
- ast (2.4.0)
21
- axiom-types (0.1.1)
22
- descendants_tracker (~> 0.0.4)
23
- ice_nine (~> 0.11.0)
24
- thread_safe (~> 0.3, >= 0.3.1)
25
- brakeman (4.7.2)
26
- bson (4.7.1)
27
- code_analyzer (0.5.1)
20
+ ast (2.4.2)
21
+ brakeman (5.0.4)
22
+ bson (4.12.1)
23
+ code_analyzer (0.5.2)
28
24
  sexp_processor
29
- codeclimate-engine-rb (0.4.1)
30
- virtus (~> 1.0)
31
- codecov (0.1.16)
32
- json
33
- simplecov
34
- url
35
- coercible (1.0.0)
36
- descendants_tracker (~> 0.0.1)
25
+ codecov (0.5.2)
26
+ simplecov (>= 0.15, < 0.22)
37
27
  colorize (0.8.1)
38
- concurrent-ruby (1.1.6)
28
+ concurrent-ruby (1.1.9)
39
29
  cornucopia (0.1.56)
40
30
  activesupport (> 4.0, < 6.0)
41
- database_cleaner (1.8.2)
42
- descendants_tracker (0.0.4)
43
- thread_safe (~> 0.3, >= 0.3.1)
44
- diff-lcs (1.3)
45
- docile (1.3.2)
46
- equalizer (0.0.11)
31
+ database_cleaner (1.8.5)
32
+ diff-lcs (1.4.4)
33
+ docile (1.4.0)
47
34
  erubis (2.7.0)
48
- faraday (1.0.0)
35
+ faraday (1.4.3)
36
+ faraday-em_http (~> 1.0)
37
+ faraday-em_synchrony (~> 1.0)
38
+ faraday-excon (~> 1.1)
39
+ faraday-net_http (~> 1.0)
40
+ faraday-net_http_persistent (~> 1.1)
49
41
  multipart-post (>= 1.2, < 3)
50
- fasterer (0.8.2)
42
+ ruby2_keywords (>= 0.0.4)
43
+ faraday-em_http (1.0.0)
44
+ faraday-em_synchrony (1.0.0)
45
+ faraday-excon (1.1.0)
46
+ faraday-net_http (1.0.1)
47
+ faraday-net_http_persistent (1.2.0)
48
+ fasterer (0.9.0)
51
49
  colorize (~> 0.7)
52
50
  ruby_parser (>= 3.14.1)
53
- gem-release (2.1.1)
54
- gitlab (4.13.1)
55
- httparty (~> 0.14, >= 0.14.0)
51
+ gem-release (2.2.2)
52
+ gitlab (4.17.0)
53
+ httparty (~> 0.18)
56
54
  terminal-table (~> 1.5, >= 1.5.1)
57
- httparty (0.17.3)
55
+ httparty (0.18.1)
58
56
  mime-types (~> 3.0)
59
57
  multi_xml (>= 0.5.2)
60
- i18n (0.9.5)
58
+ i18n (1.8.10)
61
59
  concurrent-ruby (~> 1.0)
62
- ice_nine (0.11.2)
63
- jaro_winkler (1.5.4)
64
- json (2.3.0)
60
+ json (2.5.1)
65
61
  kwalify (0.7.2)
66
62
  mime-types (3.3.1)
67
63
  mime-types-data (~> 3.2015)
68
- mime-types-data (3.2019.1009)
69
- minitest (5.14.0)
70
- mongo (2.11.3)
71
- bson (>= 4.4.2, < 5.0.0)
72
- mongoid (6.1.1)
73
- activemodel (~> 5.0)
74
- mongo (>= 2.4.1, < 3.0.0)
64
+ mime-types-data (3.2021.0704)
65
+ minitest (5.14.4)
66
+ mongo (2.14.0)
67
+ bson (>= 4.8.2, < 5.0.0)
68
+ mongoid (7.0.2)
69
+ activemodel (>= 5.1, < 6.0.0)
70
+ mongo (>= 2.5.1, < 3.0.0)
75
71
  multi_xml (0.6.0)
76
72
  multipart-post (2.1.1)
77
- octokit (4.16.0)
73
+ octokit (4.21.0)
78
74
  faraday (>= 0.9)
79
75
  sawyer (~> 0.8.0, >= 0.5.3)
80
- parallel (1.19.1)
81
- parser (2.7.0.2)
82
- ast (~> 2.4.0)
83
- pronto (0.10.0)
84
- gitlab (~> 4.0, >= 4.0.0)
76
+ parallel (1.20.1)
77
+ parser (3.0.2.0)
78
+ ast (~> 2.4.1)
79
+ pronto (0.11.0)
80
+ gitlab (~> 4.4, >= 4.4.0)
85
81
  httparty (>= 0.13.7)
86
82
  octokit (~> 4.7, >= 4.7.0)
87
83
  rainbow (>= 2.2, < 4.0)
88
- rugged (~> 0.24, >= 0.23.0)
89
- thor (~> 0.20.0)
90
- pronto-brakeman (0.10.0)
84
+ rexml (~> 3.2)
85
+ rugged (>= 0.23.0, < 1.1.0)
86
+ thor (>= 0.20.3, < 2.0)
87
+ pronto-brakeman (0.11.0)
91
88
  brakeman (>= 3.2.0)
92
- pronto (~> 0.10.0)
89
+ pronto (~> 0.11.0)
93
90
  pronto-circleci (1.0.1)
94
91
  pronto (~> 0.9)
95
- pronto-fasterer (0.10.0)
96
- fasterer (~> 0.3, >= 0.3.0)
97
- pronto (~> 0.10.0)
98
- pronto-rails_best_practices (0.10.0)
99
- pronto (~> 0.10.0)
92
+ pronto-fasterer (0.11.1)
93
+ fasterer (~> 0.9.0)
94
+ pronto (~> 0.11.0)
95
+ pronto-rails_best_practices (0.11.0)
96
+ pronto (~> 0.11.0)
100
97
  rails_best_practices (~> 1.16, >= 1.15.0)
101
- pronto-reek (0.10.0)
102
- pronto (~> 0.10.0)
103
- reek (>= 4.2, < 6.0)
104
- pronto-rubocop (0.10.0)
105
- pronto (~> 0.10.0)
106
- rubocop (~> 0.50, >= 0.49.1)
107
- psych (3.1.0)
108
- public_suffix (4.0.3)
109
- rails_best_practices (1.19.5)
98
+ pronto-reek (0.11.0)
99
+ pronto (~> 0.11.0)
100
+ reek (>= 4.2, < 7.0)
101
+ pronto-rubocop (0.11.1)
102
+ pronto (~> 0.11.0)
103
+ rubocop (>= 0.63.1, < 2.0)
104
+ psych (3.3.2)
105
+ public_suffix (4.0.6)
106
+ rails_best_practices (1.21.0)
110
107
  activesupport
111
- code_analyzer (>= 0.5.1)
108
+ code_analyzer (>= 0.5.2)
112
109
  erubis
113
110
  i18n
114
111
  json
115
112
  require_all (~> 3.0)
116
113
  ruby-progressbar
117
114
  rainbow (3.0.0)
118
- rake (13.0.1)
119
- reek (5.6.0)
120
- codeclimate-engine-rb (~> 0.4.0)
115
+ rake (13.0.4)
116
+ reek (6.0.4)
121
117
  kwalify (~> 0.7.0)
122
- parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
123
- psych (~> 3.1.0)
118
+ parser (~> 3.0.0)
119
+ psych (~> 3.1)
124
120
  rainbow (>= 2.0, < 4.0)
121
+ regexp_parser (2.1.1)
125
122
  require_all (3.0.0)
126
- rspec (3.9.0)
127
- rspec-core (~> 3.9.0)
128
- rspec-expectations (~> 3.9.0)
129
- rspec-mocks (~> 3.9.0)
130
- rspec-core (3.9.1)
131
- rspec-support (~> 3.9.1)
132
- rspec-expectations (3.9.0)
123
+ rexml (3.2.5)
124
+ rspec (3.10.0)
125
+ rspec-core (~> 3.10.0)
126
+ rspec-expectations (~> 3.10.0)
127
+ rspec-mocks (~> 3.10.0)
128
+ rspec-core (3.10.1)
129
+ rspec-support (~> 3.10.0)
130
+ rspec-expectations (3.10.1)
133
131
  diff-lcs (>= 1.2.0, < 2.0)
134
- rspec-support (~> 3.9.0)
135
- rspec-mocks (3.9.1)
132
+ rspec-support (~> 3.10.0)
133
+ rspec-mocks (3.10.2)
136
134
  diff-lcs (>= 1.2.0, < 2.0)
137
- rspec-support (~> 3.9.0)
138
- rspec-support (3.9.2)
135
+ rspec-support (~> 3.10.0)
136
+ rspec-support (3.10.2)
139
137
  rspec_junit_formatter (0.4.1)
140
138
  rspec-core (>= 2, < 4, != 2.12.0)
141
- rubocop (0.78.0)
142
- jaro_winkler (~> 1.5.1)
139
+ rubocop (1.18.3)
143
140
  parallel (~> 1.10)
144
- parser (>= 2.6)
141
+ parser (>= 3.0.0.0)
145
142
  rainbow (>= 2.2.2, < 4.0)
143
+ regexp_parser (>= 1.8, < 3.0)
144
+ rexml
145
+ rubocop-ast (>= 1.7.0, < 2.0)
146
146
  ruby-progressbar (~> 1.7)
147
- unicode-display_width (>= 1.4.0, < 1.7)
148
- rubocop-performance (1.5.2)
149
- rubocop (>= 0.71.0)
150
- ruby-progressbar (1.10.1)
151
- ruby_parser (3.14.2)
152
- sexp_processor (~> 4.9)
153
- rugged (0.28.4.1)
147
+ unicode-display_width (>= 1.4.0, < 3.0)
148
+ rubocop-ast (1.8.0)
149
+ parser (>= 3.0.1.1)
150
+ rubocop-performance (1.11.4)
151
+ rubocop (>= 1.7.0, < 2.0)
152
+ rubocop-ast (>= 0.4.0)
153
+ ruby-progressbar (1.11.0)
154
+ ruby2_keywords (0.0.4)
155
+ ruby_parser (3.16.0)
156
+ sexp_processor (~> 4.15, >= 4.15.1)
157
+ rugged (1.0.1)
154
158
  sawyer (0.8.2)
155
159
  addressable (>= 2.3.5)
156
160
  faraday (> 0.8, < 2.0)
157
- sexp_processor (4.14.1)
158
- simplecov (0.18.1)
161
+ sexp_processor (4.15.3)
162
+ simplecov (0.21.2)
159
163
  docile (~> 1.1)
160
- simplecov-html (~> 0.11.0)
161
- simplecov-html (0.11.0)
164
+ simplecov-html (~> 0.11)
165
+ simplecov_json_formatter (~> 0.1)
166
+ simplecov-html (0.12.3)
162
167
  simplecov-rcov (0.2.3)
163
168
  simplecov (>= 0.4.1)
169
+ simplecov_json_formatter (0.1.3)
164
170
  terminal-table (1.8.0)
165
171
  unicode-display_width (~> 1.1, >= 1.1.1)
166
- thor (0.20.3)
172
+ thor (1.1.0)
167
173
  thread_safe (0.3.6)
168
- timecop (0.9.1)
169
- tzinfo (1.2.6)
174
+ timecop (0.9.4)
175
+ tzinfo (1.2.9)
170
176
  thread_safe (~> 0.1)
171
- unicode-display_width (1.6.1)
172
- url (0.3.2)
173
- virtus (1.0.5)
174
- axiom-types (~> 0.1)
175
- coercible (~> 1.0)
176
- descendants_tracker (~> 0.0, >= 0.0.3)
177
- equalizer (~> 0.0, >= 0.0.9)
177
+ unicode-display_width (1.7.0)
178
178
 
179
179
  PLATFORMS
180
180
  ruby
181
181
 
182
182
  DEPENDENCIES
183
183
  acts-as-taggable-on-mongoid!
184
- codecov (~> 0.1.0, ~> 0.1)
184
+ codecov (~> 0.5.1, ~> 0.1)
185
185
  cornucopia
186
186
  database_cleaner
187
187
  gem-release
data/README.md CHANGED
@@ -190,6 +190,7 @@ end
190
190
  class MyTaggable
191
191
  include ::Mongoid::Document
192
192
 
193
+ # See lib/acts_as_taggable_on_mongoid/taggable.rb for more details on options.
193
194
  acts_as_taggable_on :my_tags,
194
195
  :your_tags,
195
196
  :other_tags,
@@ -32,9 +32,9 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  spec.add_dependency "activesupport", ">= 5.0"
35
- spec.add_dependency "mongoid", ">= 6.1.1", "<= 7.0.2"
35
+ spec.add_dependency "mongoid", ">= 6.1.1", "< 8.0"
36
36
 
37
- spec.add_development_dependency "codecov", "~> 0.1", "~> 0.1.0"
37
+ spec.add_development_dependency "codecov", "~> 0.1", "~> 0.5.1"
38
38
  spec.add_development_dependency "cornucopia"
39
39
  spec.add_development_dependency "database_cleaner"
40
40
  spec.add_development_dependency "pronto"
@@ -36,7 +36,7 @@ module ActsAsTaggableOnMongoid
36
36
  end
37
37
 
38
38
  autoload_under :Taggable do
39
- # autoload :Cache
39
+ autoload :Cache
40
40
  # autoload :Collection
41
41
  autoload :Core
42
42
  autoload :Changeable
@@ -57,6 +57,7 @@ module ActsAsTaggableOnMongoid
57
57
 
58
58
  autoload_under "models/concerns" do
59
59
  autoload :TagFields
60
+ autoload :TagHooks
60
61
  autoload :TagAssociations
61
62
  autoload :TagValidations
62
63
  autoload :TagScopes
@@ -9,7 +9,7 @@ module ActsAsTaggableOnMongoid
9
9
  included do
10
10
  ### ASSOCIATIONS:
11
11
 
12
- has_many :taggings, dependent: :destroy, class_name: "ActsAsTaggableOnMongoid::Models::Tagging"
12
+ has_many :taggings, dependent: :destroy, class_name: "ActsAsTaggableOnMongoid::Models::Tagging", inverse_of: :tag
13
13
  belongs_to :owner, polymorphic: true, optional: true, index: true
14
14
 
15
15
  after_save :atom_unset_blank_owner
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActsAsTaggableOnMongoid
4
+ module Models
5
+ module Concerns
6
+ # Update and Destroy hooks for tags to update denormalized data.
7
+ #
8
+ # NOTE: If the tag is cached AND owned, assumptions are made about the
9
+ # relationship of a Tag to the Taggings and the taggable_type.
10
+ #
11
+ # Specifically, the taggable_type is assumed to have an ID field that
12
+ # matches the owner. This field can be specified in the tag_definition
13
+ # as owner_id_field.
14
+ #
15
+ # If there isn't a simple relationship like this then override the following
16
+ # methods to update the cached data properly:
17
+ # * remove_cached_taggings
18
+ # * update_cached_taggings
19
+ module TagHooks
20
+ extend ActiveSupport::Concern
21
+
22
+ included do
23
+ after_update :denormalize_tag_name
24
+ after_destroy :remove_cached_taggings
25
+ end
26
+
27
+ private
28
+
29
+ def denormalize_tag_name
30
+ return unless name_changed?
31
+
32
+ update_taggings
33
+ update_cached_taggings
34
+ end
35
+
36
+ def update_taggings
37
+ taggings.update_all(tag_name: name)
38
+ end
39
+
40
+ def remove_cached_taggings
41
+ return if tag_definition.blank?
42
+ return unless tag_definition.cached_in_model?
43
+
44
+ cached_fields_query(name).update_all("$pull" => { "cached_#{tag_definition.tag_list_name}" => name })
45
+ end
46
+
47
+ def update_cached_taggings
48
+ return if tag_definition.blank?
49
+ return unless tag_definition.cached_in_model?
50
+
51
+ cached_fields_query(name_was).update_all("$set" => { "cached_#{tag_definition.tag_list_name}.$" => name })
52
+ end
53
+
54
+ def cached_fields_query(chached_field_value)
55
+ query = { "cached_#{tag_definition.tag_list_name}" => chached_field_value }
56
+
57
+ if owner_id.present?
58
+ id_field = tag_definition.owner_id_field || "#{owner_type.underscore}_id"
59
+
60
+ query[id_field] = owner_id
61
+ end
62
+
63
+ taggable_type.constantize.unscoped.where(query)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -22,19 +22,15 @@ module ActsAsTaggableOnMongoid
22
22
  return [] if list.empty?
23
23
 
24
24
  list.map do |tag_name|
25
- begin
26
- tries ||= 3
27
-
28
- find_or_create_tag(tag_name, tag_definition, owner)
29
- rescue Mongoid::Errors::Validations
30
- # :nocov:
31
- if (tries -= 1).positive?
32
- retry
33
- end
34
-
35
- raise ActsAsTaggableOnMongoid::Errors::DuplicateTagError.new, "'#{tag_name}' has already been taken"
36
- # :nocov:
25
+ tries ||= 3
26
+
27
+ find_or_create_tag(tag_name, tag_definition, owner)
28
+ rescue StandardError
29
+ if (tries -= 1).positive?
30
+ retry
37
31
  end
32
+
33
+ raise
38
34
  end
39
35
  end
40
36
 
@@ -52,8 +48,6 @@ module ActsAsTaggableOnMongoid
52
48
  string.mb_chars
53
49
  end
54
50
 
55
- private
56
-
57
51
  def find_or_create_tag(tag_name, tag_definition, owner)
58
52
  existing_tag = tag_definition.tags_table.for_tag(tag_definition).named(tag_name).owned_by(owner).first
59
53
 
@@ -75,6 +69,12 @@ module ActsAsTaggableOnMongoid
75
69
  def to_s
76
70
  name
77
71
  end
72
+
73
+ private
74
+
75
+ def tag_definition
76
+ @tag_definition ||= taggable_type.constantize.tag_types[context]
77
+ end
78
78
  end
79
79
  end
80
80
  end
@@ -12,6 +12,7 @@ module ActsAsTaggableOnMongoid
12
12
  include ActsAsTaggableOnMongoid::Models::Concerns::TagAssociations
13
13
  include ActsAsTaggableOnMongoid::Models::Concerns::TagValidations
14
14
  include ActsAsTaggableOnMongoid::Models::Concerns::TagScopes
15
+ include ActsAsTaggableOnMongoid::Models::Concerns::TagHooks
15
16
  end
16
17
  end
17
18
  end
@@ -11,7 +11,11 @@ module ActsAsTaggableOnMongoid
11
11
 
12
12
  belongs_to :tag, counter_cache: true, inverse_of: :taggings
13
13
  belongs_to :tagger, polymorphic: true, optional: true
14
- belongs_to :taggable, polymorphic: true
14
+
15
+ # Tags and Taggings are created in an after_save event on taggable.
16
+ # If autosave is not false, then this will cause the taggable object
17
+ # to be saved AGAIN, that could cause a number of unwanted side-effects.
18
+ belongs_to :taggable, polymorphic: true, autosave: false
15
19
 
16
20
  before_validation :atom_unset_blank_owner
17
21
  end
@@ -18,7 +18,14 @@ module ActsAsTaggableOnMongoid
18
18
  # * preserve_tag_order
19
19
  # If true, the _list accessor will save and returns tags in the order they are added to the object.
20
20
  # * cached_in_model
21
- # Not currently supported
21
+ # If true, a field is added to de-normalize/cache the list into. Can also be a hash with options:
22
+ # field: The name of the field to cache the list in
23
+ # as_list: true/false - If the cached value should be an Array or a String. No order is guaranteed
24
+ # in either case.
25
+ # Defaults to true.
26
+ # * owner_id_field
27
+ # If cached_in_model is true, if a tag is owned, this is the field that will be checked for a matching
28
+ # owner ID for tag updates and deletes.
22
29
  # * force_lowercase
23
30
  # If true, values stored for tags will first be downcased to make the values effectively case-insensitive
24
31
  # * force_parameterize
@@ -122,7 +129,7 @@ module ActsAsTaggableOnMongoid
122
129
  ActsAsTaggableOnMongoid::Taggable::Changeable,
123
130
  ActsAsTaggableOnMongoid::Taggable::TaggedWith,
124
131
  # include Collection - not sure we will need as done here. Need to think more on this one.
125
- # include Cache - TODO: Add this.
132
+ ActsAsTaggableOnMongoid::Taggable::Cache,
126
133
  # include Related - TODO: Add this.
127
134
  ActsAsTaggableOnMongoid::Taggable::TaggerRelation,
128
135
  ActsAsTaggableOnMongoid::Taggable::ListTags].each do |include_module|
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActsAsTaggableOnMongoid
4
+ module Taggable
5
+ # A collection of generic methods which use the tag definition to perform actions.
6
+ #
7
+ # These methods are called by the individual tag generated methods to do their work so that
8
+ # the code can be defined in only one location and "shared" by all tags rather than putting the code
9
+ # and definitions into the dynamically defined methods directly.
10
+ #
11
+ # This module actually consists almost exclusively of utility functions
12
+
13
+ # :reek:FeatureEnvy
14
+ # :reek:UtilityFunction
15
+ module Cache
16
+ def save_cached_tag_lists
17
+ tag_types.each_value do |tag_definition|
18
+ next unless tag_definition.cached_in_model?
19
+ next unless tag_list_cache_set_on(tag_definition)
20
+
21
+ list = all_tags_list_on(tag_definition)
22
+
23
+ list = list.to_s unless tag_definition.cached_in_model_as_list?
24
+
25
+ public_send("#{tag_definition.cached_in_model_field}=", list)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -22,6 +22,7 @@ module ActsAsTaggableOnMongoid
22
22
  # attr_writer :custom_contexts
23
23
 
24
24
  after_save :save_tags
25
+ before_save :save_cached_tag_lists
25
26
  end
26
27
 
27
28
  class_methods do
@@ -171,7 +172,7 @@ module ActsAsTaggableOnMongoid
171
172
  end
172
173
 
173
174
  def all_tags_list_on(tag_definition)
174
- tag_list_on(tag_definition).flatten
175
+ tag_list_cache_on(tag_definition).flatten
175
176
  end
176
177
 
177
178
  ##
@@ -58,6 +58,7 @@ module ActsAsTaggableOnMongoid
58
58
  self.my_tag_types = new_tag_types
59
59
  tag_definition = new_tag_types[tag_type] = ActsAsTaggableOnMongoid::Taggable::TagTypeDefinition.new(self, tag_type, options)
60
60
 
61
+ tag_definition.define_cache_field
61
62
  tag_definition.define_base_relations
62
63
  tag_definition.define_relations
63
64
  tag_definition.add_tag_list
@@ -37,6 +37,7 @@ module ActsAsTaggableOnMongoid
37
37
  cached_in_model
38
38
  force_lowercase
39
39
  force_parameterize
40
+ owner_id_field
40
41
  remove_unused_tags
41
42
  tags_table
42
43
  taggings_table].each_with_object({}) { |dup_key, opts_hash| opts_hash[dup_key] = tag_definition.public_send(dup_key) }
@@ -76,6 +77,18 @@ module ActsAsTaggableOnMongoid
76
77
  end
77
78
  end
78
79
 
80
+ def define_cache_field
81
+ tag_definition = self
82
+
83
+ return unless tag_definition.cached_in_model?
84
+
85
+ owner.class_eval do
86
+ field_type = tag_definition.cached_in_model_as_list? ? Array : String
87
+
88
+ field tag_definition.cached_in_model_field, type: field_type
89
+ end
90
+ end
91
+
79
92
  def define_base_relations
80
93
  tag_definition = self
81
94
 
@@ -177,6 +190,7 @@ module ActsAsTaggableOnMongoid
177
190
  :cached_in_model,
178
191
  :force_lowercase,
179
192
  :force_parameterize,
193
+ :owner_id_field,
180
194
  :remove_unused_tags,
181
195
  :tags_table,
182
196
  :taggings_table,
@@ -6,6 +6,7 @@ module ActsAsTaggableOnMongoid
6
6
  # This module defines methods used to evaluate the attributes of the Tag Type Definition
7
7
  module Attributes
8
8
  attr_reader :cached_in_model,
9
+ :owner_id_field,
9
10
  :default
10
11
 
11
12
  def parser
@@ -52,6 +53,14 @@ module ActsAsTaggableOnMongoid
52
53
  end
53
54
  end
54
55
 
56
+ def cached_in_model_field
57
+ @cached_in_model_field ||= cache_hash.fetch(:field) { "cached_#{tag_list_name}" }
58
+ end
59
+
60
+ def cached_in_model_as_list?
61
+ @cached_in_model_as_list ||= cache_hash.fetch(:as_list) { true }
62
+ end
63
+
55
64
  alias preserve_tag_order? preserve_tag_order
56
65
  alias cached_in_model? cached_in_model
57
66
  alias force_lowercase? force_lowercase
@@ -103,6 +112,10 @@ module ActsAsTaggableOnMongoid
103
112
 
104
113
  private
105
114
 
115
+ def cache_hash
116
+ @cache_hash ||= cached_in_model.is_a?(Hash) ? cached_in_model : {}
117
+ end
118
+
106
119
  def tagger_params
107
120
  return @tagger_params if defined?(@tagger_params)
108
121
 
@@ -101,7 +101,7 @@ module ActsAsTaggableOnMongoid
101
101
  def taggable=(value)
102
102
  @taggable = value
103
103
 
104
- tagger_tag_lists.values.each do |tag_list|
104
+ tagger_tag_lists.each_value do |tag_list|
105
105
  tag_list.taggable = taggable
106
106
  end
107
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsTaggableOnMongoid
4
- VERSION = "6.1.1.7"
4
+ VERSION = "6.1.1.12"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1.7
4
+ version: 6.1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealNobody
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-19 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -31,9 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 6.1.1
34
- - - "<="
34
+ - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 7.0.2
36
+ version: '8.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -41,9 +41,9 @@ dependencies:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  version: 6.1.1
44
- - - "<="
44
+ - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 7.0.2
46
+ version: '8.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: codecov
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  version: '0.1'
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 0.1.0
56
+ version: 0.5.1
57
57
  type: :development
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,7 +63,7 @@ dependencies:
63
63
  version: '0.1'
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: 0.1.0
66
+ version: 0.5.1
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: cornucopia
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -334,6 +334,7 @@ files:
334
334
  - lib/acts_as_taggable_on_mongoid/generic_parser.rb
335
335
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_associations.rb
336
336
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_fields.rb
337
+ - lib/acts_as_taggable_on_mongoid/models/concerns/tag_hooks.rb
337
338
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_methods.rb
338
339
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_migration.rb
339
340
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_model.rb
@@ -350,6 +351,7 @@ files:
350
351
  - lib/acts_as_taggable_on_mongoid/models/tagging.rb
351
352
  - lib/acts_as_taggable_on_mongoid/tag_list.rb
352
353
  - lib/acts_as_taggable_on_mongoid/taggable.rb
354
+ - lib/acts_as_taggable_on_mongoid/taggable/cache.rb
353
355
  - lib/acts_as_taggable_on_mongoid/taggable/changeable.rb
354
356
  - lib/acts_as_taggable_on_mongoid/taggable/core.rb
355
357
  - lib/acts_as_taggable_on_mongoid/taggable/list_tags.rb
@@ -375,7 +377,7 @@ homepage: http://www.cardtapp.com
375
377
  licenses:
376
378
  - MIT
377
379
  metadata: {}
378
- post_install_message:
380
+ post_install_message:
379
381
  rdoc_options: []
380
382
  require_paths:
381
383
  - lib
@@ -390,8 +392,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
392
  - !ruby/object:Gem::Version
391
393
  version: '0'
392
394
  requirements: []
393
- rubygems_version: 3.0.3
394
- signing_key:
395
+ rubygems_version: 3.1.2
396
+ signing_key:
395
397
  specification_version: 4
396
398
  summary: A partial mongoid implementation of tagging based on/inspired by acts-as-taggable-on.
397
399
  test_files: []