easy_tags 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/Appraisals +5 -5
- data/CHANGELOG.md +27 -1
- data/easy_tags.gemspec +4 -3
- data/gemfiles/activerecord_5.1.gemfile +4 -4
- data/gemfiles/activerecord_5.2.gemfile +4 -4
- data/gemfiles/activerecord_6.0.gemfile +8 -0
- data/lib/easy_tags.rb +1 -0
- data/lib/easy_tags/dirty_methods.rb +26 -0
- data/lib/easy_tags/taggable_context.rb +47 -6
- data/lib/easy_tags/taggable_context_methods.rb +1 -1
- data/lib/easy_tags/taggable_methods.rb +2 -16
- data/lib/easy_tags/version.rb +1 -1
- metadata +39 -12
- data/gemfiles/activerecord_5.0.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff1e7a35c7c1093f9b32c7e92bc5ec1a77fec676d06e463b22827498aa58383
|
4
|
+
data.tar.gz: 1e042bd6a98e526f227aa7e98642e014e8505e7d126a4981c537fdc83240f9b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67d3dab3a3d9d65f77e3510abce3c7a3467a300726e0d109548d32c7076db64bdf3965b6044e4f7c03faaae1c2d6c0a0a13c6de04717b8ebb10df3e3f5d63c05
|
7
|
+
data.tar.gz: 5869e18439ad14d8f2f0c818e7e719907df1c70bb4db7c307db05a0b4ffd0dc4bea206e72c1d34ee6a5e8eb5ce2018dd49a794b7737b60aa9da1bc8e3b42908f
|
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,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.2.5] - 2020-06-09
|
10
|
+
### Fixed
|
11
|
+
- Added association cache invalidation after tag changes are persisted
|
12
|
+
(fixes issue with explicit reload required to refresh `context_tags`)
|
13
|
+
|
14
|
+
## [0.2.4] - 2020-06-09
|
15
|
+
### Fixed
|
16
|
+
- Fixed tags eager loading
|
17
|
+
|
18
|
+
## [0.2.3] - 2020-01-15
|
19
|
+
### Added
|
20
|
+
- Rails 6.0 support
|
21
|
+
|
22
|
+
## [0.2.2] - 2019-10-24
|
23
|
+
### Fixed
|
24
|
+
- Fixed inspect and compare for context objects (delegate to tags list) that may have affected debug and testing
|
25
|
+
|
26
|
+
## [0.2.1] - 2019-10-24
|
27
|
+
### Fixed
|
28
|
+
- Fixed `.add` and `.remove` methods not implementing properly dirty behavior
|
29
|
+
|
9
30
|
## [0.2.0] - 2019-09-12
|
10
31
|
### Added
|
11
32
|
- `[context]_list_persisted` interface method for accessing persisted/previous tag list string
|
@@ -13,6 +34,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
13
34
|
## [0.1.0] - 2019-07-15
|
14
35
|
Initial release
|
15
36
|
|
16
|
-
[Unreleased]: https://github.com/iiwo/easy_tagscompare/v0.2.
|
37
|
+
[Unreleased]: https://github.com/iiwo/easy_tagscompare/v0.2.5...HEAD
|
38
|
+
[0.2.5]: https://github.com/iiwo/easy_tags/compare/v0.2.4...v0.2.5
|
39
|
+
[0.2.4]: https://github.com/iiwo/easy_tags/compare/v0.2.3...v0.2.4
|
40
|
+
[0.2.3]: https://github.com/iiwo/easy_tags/compare/v0.2.2...v0.2.3
|
41
|
+
[0.2.2]: https://github.com/iiwo/easy_tags/compare/v0.2.1...v0.2.2
|
42
|
+
[0.2.1]: https://github.com/iiwo/easy_tags/compare/v0.2.0...v0.2.1
|
17
43
|
[0.2.0]: https://github.com/iiwo/easy_tags/compare/v0.1.0...v0.2.0
|
18
44
|
[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', '
|
31
|
-
spec.add_runtime_dependency 'activesupport', '
|
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'
|
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
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem
|
6
|
-
gem
|
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
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem
|
6
|
-
gem
|
5
|
+
gem "activerecord", "~> 5.2.0"
|
6
|
+
gem "activesupport", "~> 5.2.0"
|
7
7
|
|
8
|
-
gemspec path:
|
8
|
+
gemspec path: "../"
|
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'
|
@@ -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 [
|
5
|
+
# @param [ActiveRecord::Relation] tags_association
|
6
6
|
# @param [Proc] on_change
|
7
|
-
def initialize(context:,
|
7
|
+
def initialize(context:, tags_association:, on_change:)
|
8
8
|
self.context = context
|
9
|
-
self.
|
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 ||=
|
25
|
+
@persisted_tags ||= preloaded_persisted_tags
|
26
26
|
end
|
27
27
|
|
28
28
|
# @param [String, Symbol] value
|
@@ -30,7 +30,7 @@ module EasyTags
|
|
30
30
|
def update(value)
|
31
31
|
@tags = TagList.new(value)
|
32
32
|
|
33
|
-
|
33
|
+
notify_change
|
34
34
|
end
|
35
35
|
|
36
36
|
# @return [TagList]
|
@@ -47,10 +47,51 @@ module EasyTags
|
|
47
47
|
def refresh
|
48
48
|
@tags = nil
|
49
49
|
@persisted_tags = nil
|
50
|
+
tags_association.reset
|
50
51
|
end
|
51
52
|
|
53
|
+
# Add tags to the tag_list. Duplicate or blank tags will be ignored.
|
54
|
+
#
|
55
|
+
# Example:
|
56
|
+
# tag_list.add('Fun', 'Happy')
|
57
|
+
def add(*names)
|
58
|
+
tags.add(*names).tap do
|
59
|
+
notify_change
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Remove item from list
|
64
|
+
#
|
65
|
+
# Example:
|
66
|
+
# tag_list.remove('Issues')
|
67
|
+
def remove(value)
|
68
|
+
tags.remove(value).tap do
|
69
|
+
notify_change
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
delegate :==, :<=>, :to_s, :inspect, :hash, to: :tags
|
74
|
+
|
52
75
|
private
|
53
76
|
|
54
|
-
attr_accessor :context, :
|
77
|
+
attr_accessor :context, :tags_association, :on_change
|
78
|
+
|
79
|
+
def respond_to_missing?(name, _include_private = false)
|
80
|
+
tags.respond_to?(name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def method_missing(name, *args, &block)
|
84
|
+
return super unless respond_to_missing?(name)
|
85
|
+
|
86
|
+
tags.send(name, *args, &block)
|
87
|
+
end
|
88
|
+
|
89
|
+
def notify_change
|
90
|
+
on_change.call(self) if changed?
|
91
|
+
end
|
92
|
+
|
93
|
+
def preloaded_persisted_tags
|
94
|
+
TagList.new(tags_association.map(&:name))
|
95
|
+
end
|
55
96
|
end
|
56
97
|
end
|
@@ -14,14 +14,6 @@ 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
|
|
@@ -65,18 +57,12 @@ module EasyTags
|
|
65
57
|
end
|
66
58
|
end
|
67
59
|
|
68
|
-
|
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
|
-
|
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
|
}
|
data/lib/easy_tags/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iwo Dziechciarow
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-09 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:
|
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:
|
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
|
@@ -201,7 +228,7 @@ 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.
|
231
|
+
rubygems_version: 3.0.8
|
205
232
|
signing_key:
|
206
233
|
specification_version: 4
|
207
234
|
summary: EasyTags allows you to tag a single model on several contexts
|