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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +2 -1
  3. data/.rubocop.yml +8 -10
  4. data/.ruby-version +1 -1
  5. data/Gemfile.lock +76 -82
  6. data/README.md +102 -28
  7. data/acts-as-taggable-on-mongoid.gemspec +3 -4
  8. data/lib/acts-as-taggable-on-mongoid.rb +9 -3
  9. data/lib/acts_as_taggable_on_mongoid/models/concerns/tag_associations.rb +12 -0
  10. data/lib/acts_as_taggable_on_mongoid/models/concerns/tag_fields.rb +4 -1
  11. data/lib/acts_as_taggable_on_mongoid/models/concerns/tag_methods.rb +21 -12
  12. data/lib/acts_as_taggable_on_mongoid/models/concerns/tag_migration.rb +46 -0
  13. data/lib/acts_as_taggable_on_mongoid/models/concerns/tag_scopes.rb +3 -2
  14. data/lib/acts_as_taggable_on_mongoid/models/concerns/tag_validations.rb +1 -1
  15. data/lib/acts_as_taggable_on_mongoid/models/concerns/tagging_associations.rb +13 -1
  16. data/lib/acts_as_taggable_on_mongoid/models/concerns/tagging_fields.rb +4 -2
  17. data/lib/acts_as_taggable_on_mongoid/models/concerns/tagging_methods.rb +2 -2
  18. data/lib/acts_as_taggable_on_mongoid/models/concerns/tagging_migration.rb +46 -0
  19. data/lib/acts_as_taggable_on_mongoid/models/concerns/tagging_scopes.rb +7 -5
  20. data/lib/acts_as_taggable_on_mongoid/models/concerns/tagging_validations.rb +2 -6
  21. data/lib/acts_as_taggable_on_mongoid/tag_list.rb +91 -4
  22. data/lib/acts_as_taggable_on_mongoid/taggable.rb +13 -1
  23. data/lib/acts_as_taggable_on_mongoid/taggable/changeable.rb +5 -4
  24. data/lib/acts_as_taggable_on_mongoid/taggable/core.rb +156 -34
  25. data/lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition.rb +29 -50
  26. data/lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/attributes.rb +57 -6
  27. data/lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/changeable.rb +52 -39
  28. data/lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/list_methods.rb +77 -0
  29. data/lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/names.rb +12 -0
  30. data/lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query/all_tags_query.rb +1 -1
  31. data/lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query/any_tags_query.rb +1 -1
  32. data/lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query/exclude_tags_query.rb +1 -1
  33. data/lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query/match_all_tags_query.rb +1 -1
  34. data/lib/acts_as_taggable_on_mongoid/taggable/tagger_relation.rb +53 -0
  35. data/lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb +9 -7
  36. data/lib/acts_as_taggable_on_mongoid/tagger.rb +67 -0
  37. data/lib/acts_as_taggable_on_mongoid/tagger/tag_methods.rb +74 -0
  38. data/lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb +171 -0
  39. data/lib/acts_as_taggable_on_mongoid/version.rb +1 -1
  40. metadata +18 -26
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActsAsTaggableOnMongoid
4
+ module Tagger
5
+ # A module defining Tagger methods allowing the Tagger object to tag Taggable objects
6
+ #
7
+ # This module is dynamically added to a model when the model calls acts_as_tagger
8
+
9
+ # :reek:DataClump
10
+ module TagMethods
11
+ ##
12
+ # Taggs the passed in taggable object with the tag values passed in to it.
13
+ #
14
+ # Parameters:
15
+ # taggable - the object to tag
16
+ # non-hash values - the values to use to tag taggable with
17
+ # {options}
18
+ # with: - Alternative to non-hash values. If found as an option it will replace
19
+ # any non-hash values. If not specified, any tags for this tagger will be
20
+ # removed from taggable
21
+ # on: - the tag list within taggable to be set. This will default to `:tag`
22
+ # parse: - Boolean indicating if the tags should be parsed. This will default to "true"
23
+ # parser: - Class to be used to parse the values.
24
+ # skip_save: - Do not save the taggable object with the new tagging.
25
+ def tag(taggable, *args)
26
+ options = atom_tag(taggable, *args)
27
+
28
+ taggable.save unless options[:skip_save]
29
+ end
30
+
31
+ ##
32
+ # tag, but uses `save!` instead of `save` to save the taggable model.
33
+ def tag!(taggable, *args)
34
+ options = atom_tag(taggable, *args)
35
+
36
+ taggable.save! unless options[:skip_save]
37
+ end
38
+
39
+ def self.atom_extract_tag_options(set_list)
40
+ options = set_list.extract_options!
41
+
42
+ options.assert_valid_keys :with,
43
+ :on,
44
+ :replace,
45
+ :parse,
46
+ :parser,
47
+ :skip_save
48
+
49
+ options[:parse] = options.fetch(:parse) { true } || options.key?(:parser)
50
+
51
+ options
52
+ end
53
+
54
+ private
55
+
56
+ # :reek:FeatureEnvy
57
+ def atom_tag(taggable, *args)
58
+ set_list = args.dup
59
+ options = ActsAsTaggableOnMongoid::Tagger::TagMethods.atom_extract_tag_options(set_list)
60
+ set_list = Array.wrap(options[:with]) if options.key?(:with)
61
+
62
+ tag_list = taggable.public_send("tagger_#{options.fetch(:on) { :tag }}_list", self)
63
+ list_options = options.slice(:parse, :parser)
64
+ if options[:replace]
65
+ tag_list.set(*set_list, list_options)
66
+ else
67
+ tag_list.add(*set_list, list_options)
68
+ end
69
+
70
+ options
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActsAsTaggableOnMongoid
4
+ # A hash like collection of tag lists grouped by tagger
5
+
6
+ # :reek:RepeatedConditional
7
+ class TaggerTagList
8
+ include Comparable
9
+
10
+ delegate :keys,
11
+ :values,
12
+ :length,
13
+ :delete,
14
+ :clear,
15
+ :each,
16
+ :each_with_object,
17
+ :detect,
18
+ :reject!,
19
+ :any?,
20
+ :each_value,
21
+ :map,
22
+ to: :tagger_tag_lists
23
+
24
+ attr_reader :taggable,
25
+ :tag_definition
26
+
27
+ def initialize(tag_definition, taggable)
28
+ @tag_definition = tag_definition
29
+ @taggable = taggable
30
+
31
+ @tagger_tag_lists = Hash.new { ActsAsTaggableOnMongoid::TagList.new_taggable_list(tag_definition, taggable) }
32
+ end
33
+
34
+ def compact!
35
+ reject! { |_key, value| value.blank? }
36
+ self
37
+ end
38
+
39
+ def compact
40
+ dup.compact!
41
+ end
42
+
43
+ def flatten
44
+ list = ActsAsTaggableOnMongoid::TagList.new_taggable_list(tag_definition, taggable)
45
+
46
+ each_value do |tag_list|
47
+ list.concat(tag_list)
48
+ end
49
+
50
+ list
51
+ end
52
+
53
+ def <=>(other)
54
+ compact!
55
+
56
+ if other.is_a?(ActsAsTaggableOnMongoid::TagList)
57
+ compare_to_tag_list(other)
58
+ elsif other.is_a?(ActsAsTaggableOnMongoid::TaggerTagList)
59
+ other.compact!
60
+
61
+ compare_to_tagger_tag_list(other)
62
+ else
63
+ super(other)
64
+ end
65
+ end
66
+
67
+ def [](tagger)
68
+ list = tagger_tag_lists[tagger]
69
+
70
+ list.tagger = tagger
71
+
72
+ tagger_tag_lists[tagger] = list
73
+ end
74
+
75
+ def []=(tagger, value)
76
+ tagger_list = self[tagger]
77
+
78
+ if value.is_a?(ActsAsTaggableOnMongoid::TagList)
79
+ tagger_list.set(value)
80
+ else
81
+ value = Array.wrap(value).dup
82
+ options = value.extract_options!
83
+ options[:parse] = options.fetch(:parse) { true }
84
+
85
+ value = [*value, options]
86
+
87
+ tagger_list.set(*value)
88
+ end
89
+ end
90
+
91
+ def dup
92
+ list = ActsAsTaggableOnMongoid::TaggerTagList.new(tag_definition, taggable)
93
+
94
+ each do |tagger, tag_list|
95
+ list[tagger].silent_concat(tag_list) if tag_list.present?
96
+ end
97
+
98
+ list
99
+ end
100
+
101
+ def taggable=(value)
102
+ @taggable = value
103
+
104
+ tagger_tag_lists.values.each do |tag_list|
105
+ tag_list.taggable = taggable
106
+ end
107
+ end
108
+
109
+ def notify_will_change
110
+ return unless taggable
111
+
112
+ taggable.tag_list_on_changed tag_definition
113
+ end
114
+
115
+ def blank?
116
+ tagger_tag_lists.values.all?(&:blank?)
117
+ end
118
+
119
+ private
120
+
121
+ attr_reader :tagger_tag_lists
122
+
123
+ def compare_tagger_tag_list_properties(other)
124
+ sub_compare = keys.length <=> other.keys.length
125
+ return sub_compare unless sub_compare&.zero?
126
+
127
+ taggable <=> other.taggable
128
+ end
129
+
130
+ def compare_to_tagger_tag_list(other)
131
+ sub_compare = compare_tagger_tag_list_properties(other)
132
+ return sub_compare unless sub_compare&.zero?
133
+
134
+ any? do |key, tag_list|
135
+ other_tag_list = other[key]
136
+
137
+ sub_compare = if tag_definition.preserve_tag_order
138
+ tag_list <=> other_tag_list
139
+ else
140
+ tag_list.sort <=> other_tag_list.sort
141
+ end
142
+
143
+ !sub_compare&.zero?
144
+ end
145
+
146
+ sub_compare
147
+ end
148
+
149
+ def compare_tag_list_properties(other)
150
+ sub_compare = tagger_tag_lists.length <=> 1
151
+ return sub_compare unless sub_compare&.zero?
152
+
153
+ sub_compare = keys.first <=> other.tagger
154
+ return sub_compare unless sub_compare&.zero?
155
+
156
+ taggable <=> other.taggable
157
+ end
158
+
159
+ def compare_to_tag_list(other)
160
+ sub_compare = compare_tag_list_properties(other)
161
+ return sub_compare unless sub_compare&.zero?
162
+
163
+ tagger_list = values.first
164
+ if tag_definition.preserve_tag_order
165
+ tagger_list <=> other
166
+ else
167
+ tagger_list.sort <=> other.sort
168
+ end
169
+ end
170
+ end
171
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsTaggableOnMongoid
4
- VERSION = "6.0.1.5"
4
+ VERSION = "6.1.1.7"
5
5
  end
metadata CHANGED
@@ -1,36 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1.5
4
+ version: 6.1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealNobody
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-09 00:00:00.000000000 Z
11
+ date: 2020-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongoid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: 6.1.1
34
34
  - - "<="
35
35
  - !ruby/object:Gem::Version
36
36
  version: 7.0.2
@@ -40,24 +40,10 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '5.2'
43
+ version: 6.1.1
44
44
  - - "<="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 7.0.2
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.16'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.16'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: codecov
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -210,14 +196,14 @@ dependencies:
210
196
  requirements:
211
197
  - - "~>"
212
198
  - !ruby/object:Gem::Version
213
- version: '12.3'
199
+ version: '13.0'
214
200
  type: :development
215
201
  prerelease: false
216
202
  version_requirements: !ruby/object:Gem::Requirement
217
203
  requirements:
218
204
  - - "~>"
219
205
  - !ruby/object:Gem::Version
220
- version: '12.3'
206
+ version: '13.0'
221
207
  - !ruby/object:Gem::Dependency
222
208
  name: rspec
223
209
  requirement: !ruby/object:Gem::Requirement
@@ -349,12 +335,14 @@ files:
349
335
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_associations.rb
350
336
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_fields.rb
351
337
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_methods.rb
338
+ - lib/acts_as_taggable_on_mongoid/models/concerns/tag_migration.rb
352
339
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_model.rb
353
340
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_scopes.rb
354
341
  - lib/acts_as_taggable_on_mongoid/models/concerns/tag_validations.rb
355
342
  - lib/acts_as_taggable_on_mongoid/models/concerns/tagging_associations.rb
356
343
  - lib/acts_as_taggable_on_mongoid/models/concerns/tagging_fields.rb
357
344
  - lib/acts_as_taggable_on_mongoid/models/concerns/tagging_methods.rb
345
+ - lib/acts_as_taggable_on_mongoid/models/concerns/tagging_migration.rb
358
346
  - lib/acts_as_taggable_on_mongoid/models/concerns/tagging_model.rb
359
347
  - lib/acts_as_taggable_on_mongoid/models/concerns/tagging_scopes.rb
360
348
  - lib/acts_as_taggable_on_mongoid/models/concerns/tagging_validations.rb
@@ -368,6 +356,7 @@ files:
368
356
  - lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition.rb
369
357
  - lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/attributes.rb
370
358
  - lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/changeable.rb
359
+ - lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/list_methods.rb
371
360
  - lib/acts_as_taggable_on_mongoid/taggable/tag_type_definition/names.rb
372
361
  - lib/acts_as_taggable_on_mongoid/taggable/tagged_with.rb
373
362
  - lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb
@@ -376,7 +365,11 @@ files:
376
365
  - lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query/base.rb
377
366
  - lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query/exclude_tags_query.rb
378
367
  - lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query/match_all_tags_query.rb
368
+ - lib/acts_as_taggable_on_mongoid/taggable/tagger_relation.rb
379
369
  - lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb
370
+ - lib/acts_as_taggable_on_mongoid/tagger.rb
371
+ - lib/acts_as_taggable_on_mongoid/tagger/tag_methods.rb
372
+ - lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb
380
373
  - lib/acts_as_taggable_on_mongoid/version.rb
381
374
  homepage: http://www.cardtapp.com
382
375
  licenses:
@@ -397,8 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
390
  - !ruby/object:Gem::Version
398
391
  version: '0'
399
392
  requirements: []
400
- rubyforge_project:
401
- rubygems_version: 2.7.6
393
+ rubygems_version: 3.0.3
402
394
  signing_key:
403
395
  specification_version: 4
404
396
  summary: A partial mongoid implementation of tagging based on/inspired by acts-as-taggable-on.