easy_tags 0.2.2 → 0.2.6

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: bb06e1ee49d89ee14b96399332522ffe2a1992d0617ffc21d0205f03d3420d4a
4
- data.tar.gz: 6d80b72229751717a9c6b2103285ba9666cad97147d1bbe6789ef3c0b75d85c2
3
+ metadata.gz: 28e114c5f8de3ceaf5728fecfe910c88464e1eb0067732a7b24bb9c7c5935c89
4
+ data.tar.gz: 064c888f328cfa05f9e3de0c6d0b0b8c90957134ef02ed97ce17140760f5de13
5
5
  SHA512:
6
- metadata.gz: 79e003d812d2f74ffdff9355ad09619cbfc8a5ea21cecccff36fcf0fee825a041897146c791bddf58c9b1b94ccf5d7704c86256c80e4666c4ae525ecf5148c4f
7
- data.tar.gz: 3804f90c2bc81ce007f59a8d710c2f2749df7cd3cc9a2316b818bb4178731700bd8830528f9c0622e1c1d948e919f7518c43380076047e8c9cdf010adffb389e
6
+ metadata.gz: 9b5e9917f9f0e40c441ec4ded539fd6f4179d9dd835d508c28f1ad137c7b968a382013d9a0169f9c6b0abcdbd2f868c000d7e80e61b0176d6dea691092d06aaa
7
+ data.tar.gz: 3265ee7814dea6f750594558e99fe8ab58c5577c61358851e77e6e2c5e480774e4cf9125b2f59ec9d9fb54b26beab0b32af99f8eee800154ae388391408a9018
data/.travis.yml CHANGED
@@ -14,16 +14,14 @@ script:
14
14
  after_script:
15
15
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
16
16
  rvm:
17
- - 2.3.8
18
- - 2.4.5
19
17
  - 2.5.3
20
18
  - 2.6.0
21
19
  - ruby-head
22
20
  gemfile:
23
21
  - Gemfile
24
- - gemfiles/activerecord_5.0.gemfile
25
22
  - gemfiles/activerecord_5.1.gemfile
26
23
  - gemfiles/activerecord_5.2.gemfile
24
+ - gemfiles/activerecord_6.0.gemfile
27
25
  matrix:
28
26
  allow_failures:
29
27
  - rvm: ruby-head
data/Appraisals CHANGED
@@ -1,8 +1,3 @@
1
- appraise 'activerecord-5.0' do
2
- gem 'activerecord', '~> 5.0.0'
3
- gem 'activesupport', '~> 5.0.0'
4
- end
5
-
6
1
  appraise 'activerecord-5.1' do
7
2
  gem 'activerecord', '~> 5.1.0'
8
3
  gem 'activesupport', '~> 5.1.0'
@@ -12,3 +7,8 @@ appraise 'activerecord-5.2' do
12
7
  gem 'activerecord', '~> 5.2.0'
13
8
  gem 'activesupport', '~> 5.2.0'
14
9
  end
10
+
11
+ appraise 'activerecord-6.0' do
12
+ gem 'activerecord', '~> 6.0.0'
13
+ gem 'activesupport', '~> 6.0.0'
14
+ end
data/CHANGELOG.md CHANGED
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.6] - 2022-01-21
10
+ ### Fixed
11
+ - Fixed bug with reload method arguments forwarding. [Issue #36](https://github.com/iiwo/easy_tags/issues/36)
12
+
13
+ ## [0.2.5] - 2020-06-09
14
+ ### Fixed
15
+ - Added association cache invalidation after tag changes are persisted
16
+ (fixes issue with explicit reload required to refresh `context_tags`)
17
+
18
+ ## [0.2.4] - 2020-06-09
19
+ ### Fixed
20
+ - Fixed tags eager loading
21
+
22
+ ## [0.2.3] - 2020-01-15
23
+ ### Added
24
+ - Rails 6.0 support
25
+
9
26
  ## [0.2.2] - 2019-10-24
10
27
  ### Fixed
11
28
  - Fixed inspect and compare for context objects (delegate to tags list) that may have affected debug and testing
@@ -21,8 +38,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
38
  ## [0.1.0] - 2019-07-15
22
39
  Initial release
23
40
 
24
- [Unreleased]: https://github.com/iiwo/easy_tagscompare/v0.2.0...HEAD
25
- [0.2.1]: https://github.com/iiwo/easy_tags/compare/v0.2.1...v0.2.2
41
+ [Unreleased]: https://github.com/iiwo/easy_tagscompare/v0.2.6...HEAD
42
+ [0.2.6]: https://github.com/iiwo/easy_tags/compare/v0.2.5...v0.2.6
43
+ [0.2.5]: https://github.com/iiwo/easy_tags/compare/v0.2.4...v0.2.5
44
+ [0.2.4]: https://github.com/iiwo/easy_tags/compare/v0.2.3...v0.2.4
45
+ [0.2.3]: https://github.com/iiwo/easy_tags/compare/v0.2.2...v0.2.3
46
+ [0.2.2]: https://github.com/iiwo/easy_tags/compare/v0.2.1...v0.2.2
26
47
  [0.2.1]: https://github.com/iiwo/easy_tags/compare/v0.2.0...v0.2.1
27
48
  [0.2.0]: https://github.com/iiwo/easy_tags/compare/v0.1.0...v0.2.0
28
49
  [0.1.0]: https://github.com/iiwo/easy_tags/releases/tag/v0.1.0
data/easy_tags.gemspec CHANGED
@@ -27,15 +27,16 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_runtime_dependency 'activerecord', '~> 5.0'
31
- spec.add_runtime_dependency 'activesupport', '~> 5.0'
30
+ spec.add_runtime_dependency 'activerecord', '>= 5.0', '< 6.1'
31
+ spec.add_runtime_dependency 'activesupport', '>= 5.0', '< 6.1'
32
32
 
33
33
  spec.add_development_dependency 'appraisal'
34
34
  spec.add_development_dependency 'database_cleaner'
35
+ spec.add_development_dependency 'db-query-matchers'
35
36
  spec.add_development_dependency 'rspec'
36
37
  spec.add_development_dependency 'rspec-rails'
37
38
  spec.add_development_dependency 'simplecov'
38
39
  spec.add_development_dependency 'simplecov-console'
39
- spec.add_development_dependency 'sqlite3', '~> 1.3.6'
40
+ spec.add_development_dependency 'sqlite3'
40
41
  end
41
42
  # rubocop:enable Metrics/BlockLength
@@ -1,8 +1,8 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
- gem 'activerecord', '~> 5.1.0'
6
- gem 'activesupport', '~> 5.1.0'
5
+ gem "activerecord", "~> 5.1.0"
6
+ gem "activesupport", "~> 5.1.0"
7
7
 
8
- gemspec path: '../'
8
+ gemspec path: "../"
@@ -1,8 +1,8 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
- gem 'activerecord', '~> 5.2.0'
6
- gem 'activesupport', '~> 5.2.0'
5
+ gem "activerecord", "~> 5.2.0"
6
+ gem "activesupport", "~> 5.2.0"
7
7
 
8
- gemspec path: '../'
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0"
6
+ gem "activesupport", "~> 6.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,26 @@
1
+ module EasyTags
2
+ # Handles dirty behaviour
3
+ module DirtyMethods
4
+ RAILS_6 = ::ActiveRecord.gem_version >= ::Gem::Version.new('6.0.0')
5
+
6
+ def _mark_dirty(context:, taggable_context:)
7
+ _set_dirty_previous_value(attribute_name: "#{context}_list", value: taggable_context.persisted_tags.to_s)
8
+ write_attribute("#{context}_list", taggable_context.tags.to_s)
9
+ attribute_will_change!("#{context}_list")
10
+ end
11
+
12
+ if RAILS_6
13
+ def _set_dirty_previous_value(attribute_name:, value:)
14
+ @attributes[attribute_name] = ActiveModel::Attribute.from_user(
15
+ attribute_name,
16
+ value,
17
+ ActiveModel::Type::Value.new
18
+ )
19
+ end
20
+ else
21
+ def _set_dirty_previous_value(attribute_name:, value:)
22
+ set_attribute_was(attribute_name, value)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,11 +2,11 @@ module EasyTags
2
2
  # Handles tag context manipulation
3
3
  class TaggableContext
4
4
  # @param [String, Symbol] context
5
- # @param [Proc] refresh_persisted_tags
5
+ # @param [ActiveRecord::Relation] tags_association
6
6
  # @param [Proc] on_change
7
- def initialize(context:, refresh_persisted_tags:, on_change:)
7
+ def initialize(context:, tags_association:, on_change:)
8
8
  self.context = context
9
- self.refresh_persisted_tags = refresh_persisted_tags
9
+ self.tags_association = tags_association
10
10
  self.on_change = on_change
11
11
  end
12
12
 
@@ -22,7 +22,7 @@ module EasyTags
22
22
 
23
23
  # @return [TagList]
24
24
  def persisted_tags
25
- @persisted_tags ||= TagList.new(refresh_persisted_tags.call)
25
+ @persisted_tags ||= preloaded_persisted_tags
26
26
  end
27
27
 
28
28
  # @param [String, Symbol] value
@@ -47,6 +47,7 @@ module EasyTags
47
47
  def refresh
48
48
  @tags = nil
49
49
  @persisted_tags = nil
50
+ tags_association.reset
50
51
  end
51
52
 
52
53
  # Add tags to the tag_list. Duplicate or blank tags will be ignored.
@@ -73,7 +74,7 @@ module EasyTags
73
74
 
74
75
  private
75
76
 
76
- attr_accessor :context, :refresh_persisted_tags, :on_change
77
+ attr_accessor :context, :tags_association, :on_change
77
78
 
78
79
  def respond_to_missing?(name, _include_private = false)
79
80
  tags.respond_to?(name)
@@ -88,5 +89,9 @@ module EasyTags
88
89
  def notify_change
89
90
  on_change.call(self) if changed?
90
91
  end
92
+
93
+ def preloaded_persisted_tags
94
+ TagList.new(tags_association.map(&:name))
95
+ end
91
96
  end
92
97
  end
@@ -14,20 +14,12 @@ module EasyTags
14
14
  inverse_of: :taggable
15
15
  )
16
16
 
17
- has_many(
18
- :base_tags,
19
- through: :taggings,
20
- source: :tag,
21
- class_name: '::EasyTags::Tag',
22
- inverse_of: :tag
23
- )
24
-
25
17
  after_save :_update_taggings, :_refresh_tagging
26
18
  after_find :_refresh_tagging
27
19
 
28
20
  # override ActiveRecord::Persistence#reload
29
21
  # to refresh tags each time the model instance gets reloaded
30
- def reload
22
+ def reload(*args)
31
23
  _refresh_tagging
32
24
  super
33
25
  end
@@ -65,18 +57,12 @@ module EasyTags
65
57
  end
66
58
  end
67
59
 
68
- def _mark_dirty(context:, taggable_context:)
69
- write_attribute("#{context}_list", taggable_context.tags.to_s)
70
- set_attribute_was("#{context}_list", taggable_context.persisted_tags.to_s)
71
- attribute_will_change!("#{context}_list")
72
- end
60
+ include DirtyMethods
73
61
 
74
62
  def _taggable_context(context)
75
63
  _taggable_contexts[context] ||= TaggableContext.new(
76
64
  context: context,
77
- refresh_persisted_tags: lambda {
78
- taggings.joins(:tag).where(context: context).pluck(:name)
79
- },
65
+ tags_association: public_send("#{context}_tags"),
80
66
  on_change: lambda { |tag_context|
81
67
  _mark_dirty(context: context, taggable_context: tag_context)
82
68
  }
@@ -1,3 +1,3 @@
1
1
  module EasyTags
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.6'.freeze
3
3
  end
data/lib/easy_tags.rb CHANGED
@@ -5,6 +5,7 @@ require 'active_record'
5
5
  module EasyTags
6
6
  extend ActiveSupport::Autoload
7
7
 
8
+ autoload :DirtyMethods, 'easy_tags/dirty_methods'
8
9
  autoload :Tag, 'easy_tags/tag'
9
10
  autoload :TaggableMethods, 'easy_tags/taggable_methods'
10
11
  autoload :TaggableContextMethods, 'easy_tags/taggable_context_methods'
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iwo Dziechciarow
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-24 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: '5.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.1'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">="
39
48
  - !ruby/object:Gem::Version
40
49
  version: '5.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.1'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: appraisal
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +78,20 @@ dependencies:
66
78
  - - ">="
67
79
  - !ruby/object:Gem::Version
68
80
  version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: db-query-matchers
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
69
95
  - !ruby/object:Gem::Dependency
70
96
  name: rspec
71
97
  requirement: !ruby/object:Gem::Requirement
@@ -126,16 +152,16 @@ dependencies:
126
152
  name: sqlite3
127
153
  requirement: !ruby/object:Gem::Requirement
128
154
  requirements:
129
- - - "~>"
155
+ - - ">="
130
156
  - !ruby/object:Gem::Version
131
- version: 1.3.6
157
+ version: '0'
132
158
  type: :development
133
159
  prerelease: false
134
160
  version_requirements: !ruby/object:Gem::Requirement
135
161
  requirements:
136
- - - "~>"
162
+ - - ">="
137
163
  - !ruby/object:Gem::Version
138
- version: 1.3.6
164
+ version: '0'
139
165
  description: Easy tagging for Rails
140
166
  email:
141
167
  - iiwo@o2.pl
@@ -159,10 +185,11 @@ files:
159
185
  - bin/console
160
186
  - bin/setup
161
187
  - easy_tags.gemspec
162
- - gemfiles/activerecord_5.0.gemfile
163
188
  - gemfiles/activerecord_5.1.gemfile
164
189
  - gemfiles/activerecord_5.2.gemfile
190
+ - gemfiles/activerecord_6.0.gemfile
165
191
  - lib/easy_tags.rb
192
+ - lib/easy_tags/dirty_methods.rb
166
193
  - lib/easy_tags/generators/default.rb
167
194
  - lib/easy_tags/options/callback.rb
168
195
  - lib/easy_tags/options/collection.rb
@@ -186,7 +213,7 @@ metadata:
186
213
  changelog_uri: https://github.com/iiwo/easy_tags/blob/master/CHANGELOG.md
187
214
  source_code_uri: https://github.com/iiwo/easy_tags
188
215
  bug_tracker_uri: https://github.com/iiwo/easy_tags/issues
189
- post_install_message:
216
+ post_install_message:
190
217
  rdoc_options: []
191
218
  require_paths:
192
219
  - lib
@@ -201,8 +228,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
228
  - !ruby/object:Gem::Version
202
229
  version: '0'
203
230
  requirements: []
204
- rubygems_version: 3.0.4
205
- signing_key:
231
+ rubygems_version: 3.2.9
232
+ signing_key:
206
233
  specification_version: 4
207
234
  summary: EasyTags allows you to tag a single model on several contexts
208
235
  test_files: []
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source 'https://rubygems.org'
4
-
5
- gem 'activerecord', '~> 5.0.0'
6
- gem 'activesupport', '~> 5.0.0'
7
-
8
- gemspec path: '../'