easy_tags 0.1.0 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9d001007c468197af668ff53d0cd2606b627e854c375b3661ef873f31679ecd
4
- data.tar.gz: 8e961637ec99daa3b300816fae2b6e4fbcf0df9228f8374f55f404075a547187
3
+ metadata.gz: 8287fdecc7f7ef46be4d02d25db0781471ce1bd039a4e6f0ed357d4ff9ba0a46
4
+ data.tar.gz: 2d3e23375449f4c229948825e6aadf8194a76bd47d00a480050140124db0fa10
5
5
  SHA512:
6
- metadata.gz: 3dfe8cc27d54a09bb33a30d05b9f666d7083af4489cc4e142e1cad79d6d5134911148eb67bcab5ffa8c996478dab2cc527073dd4d7ff53f6487447a8070cf26e
7
- data.tar.gz: f5ded6f869d9a5f5388ca3c380d2c9513fbc281219a5efb025aa95a0131c9b858e6714c7d6cd5b3f12cf22ac6ba2ccde2154bbeda129340ef8b71a533d43a9fa
6
+ metadata.gz: eef88df3c81e4f130f1a59aaad9c6c7ea74752bc8e4bdc6279f8ee716be7fd27d7f576c7c132aca38a3d3e93aa3052dc2b838a3e9f505be08a41225cbe7636da
7
+ data.tar.gz: 1302a9207d12f0980cca36d93f01595d1293456f4d2a8a28427a63857a236ad78aae83daffd4b8881c28dc2c856eadc999808cb7a2b2e0641521609f3e0651ff
@@ -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
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.4] - 2020-06-09
10
+ ### Fixed
11
+ - Fixed tags eager loading
12
+
13
+ ## [0.2.3] - 2020-01-15
14
+ ### Added
15
+ - Rails 6.0 support
16
+
17
+ ## [0.2.2] - 2019-10-24
18
+ ### Fixed
19
+ - Fixed inspect and compare for context objects (delegate to tags list) that may have affected debug and testing
20
+
21
+ ## [0.2.1] - 2019-10-24
22
+ ### Fixed
23
+ - Fixed `.add` and `.remove` methods not implementing properly dirty behavior
24
+
25
+ ## [0.2.0] - 2019-09-12
26
+ ### Added
27
+ - `[context]_list_persisted` interface method for accessing persisted/previous tag list string
28
+
29
+ ## [0.1.0] - 2019-07-15
30
+ Initial release
31
+
32
+ [Unreleased]: https://github.com/iiwo/easy_tagscompare/v0.2.4...HEAD
33
+ [0.2.4]: https://github.com/iiwo/easy_tags/compare/v0.2.3...v0.2.4
34
+ [0.2.3]: https://github.com/iiwo/easy_tags/compare/v0.2.2...v0.2.3
35
+ [0.2.2]: https://github.com/iiwo/easy_tags/compare/v0.2.1...v0.2.2
36
+ [0.2.1]: https://github.com/iiwo/easy_tags/compare/v0.2.0...v0.2.1
37
+ [0.2.0]: https://github.com/iiwo/easy_tags/compare/v0.1.0...v0.2.0
38
+ [0.1.0]: https://github.com/iiwo/easy_tags/releases/tag/v0.1.0
data/README.md CHANGED
@@ -90,12 +90,13 @@ easy_tags_on :highlights
90
90
 
91
91
  the following methods will be auto-generated and made available for your model instance (`highlights` being an example context name):
92
92
 
93
- | description | method |
94
- |------------------------------------|---------------------------|
95
- | set tags using string of tag names | `highlights_list=(value)` |
96
- | get string of tag names | `highlights_list` |
97
- | set tags with array of tag names | `highlights=(value)` |
98
- | get array of tag names | `highlights` |
93
+ | description | method |
94
+ |------------------------------------|----------------------------------|
95
+ | set tags using string of tag names | `highlights_list=(value)` |
96
+ | get string of tag names | `highlights_list` |
97
+ | get string of persisted tag names | `highlights_list_persisted` |
98
+ | set tags with array of tag names | `highlights=(value)` |
99
+ | get array of tag names | `highlights` |
99
100
 
100
101
  - the String accessor is helpful when working with client side tagging UI solutions such as ie. [select2](https://select2.org/tagging)
101
102
  - the Array accessor gives you convenient array item manipulation
@@ -2,6 +2,7 @@ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'easy_tags/version'
4
4
 
5
+ # rubocop:disable Metrics/BlockLength
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = 'easy_tags'
7
8
  spec.version = EasyTags::VERSION
@@ -12,6 +13,12 @@ Gem::Specification.new do |spec|
12
13
  spec.description = 'Easy tagging for Rails'
13
14
  spec.homepage = 'https://github.com/iiwo/easy_tags'
14
15
  spec.license = 'MIT'
16
+ spec.metadata = {
17
+ 'homepage_uri' => 'https://github.com/iiwo/easy_tags',
18
+ 'changelog_uri' => 'https://github.com/iiwo/easy_tags/blob/master/CHANGELOG.md',
19
+ 'source_code_uri' => 'https://github.com/iiwo/easy_tags',
20
+ 'bug_tracker_uri' => 'https://github.com/iiwo/easy_tags/issues'
21
+ }
15
22
 
16
23
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
24
  f.match(%r{^(test|spec|features)/})
@@ -20,14 +27,16 @@ Gem::Specification.new do |spec|
20
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
28
  spec.require_paths = ['lib']
22
29
 
23
- spec.add_runtime_dependency 'activerecord', '~> 5.0'
24
- 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'
25
32
 
26
33
  spec.add_development_dependency 'appraisal'
27
34
  spec.add_development_dependency 'database_cleaner'
35
+ spec.add_development_dependency 'db-query-matchers'
28
36
  spec.add_development_dependency 'rspec'
29
37
  spec.add_development_dependency 'rspec-rails'
30
38
  spec.add_development_dependency 'simplecov'
31
39
  spec.add_development_dependency 'simplecov-console'
32
- spec.add_development_dependency 'sqlite3', '~> 1.3.6'
40
+ spec.add_development_dependency 'sqlite3'
33
41
  end
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: "../"
@@ -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 [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
@@ -30,7 +30,7 @@ module EasyTags
30
30
  def update(value)
31
31
  @tags = TagList.new(value)
32
32
 
33
- on_change.call(self) if changed?
33
+ notify_change
34
34
  end
35
35
 
36
36
  # @return [TagList]
@@ -49,8 +49,51 @@ module EasyTags
49
49
  @persisted_tags = nil
50
50
  end
51
51
 
52
+ # Add tags to the tag_list. Duplicate or blank tags will be ignored.
53
+ #
54
+ # Example:
55
+ # tag_list.add('Fun', 'Happy')
56
+ def add(*names)
57
+ tags.add(*names).tap do
58
+ notify_change
59
+ end
60
+ end
61
+
62
+ # Remove item from list
63
+ #
64
+ # Example:
65
+ # tag_list.remove('Issues')
66
+ def remove(value)
67
+ tags.remove(value).tap do
68
+ notify_change
69
+ end
70
+ end
71
+
72
+ delegate :==, :<=>, :to_s, :inspect, :hash, to: :tags
73
+
52
74
  private
53
75
 
54
- attr_accessor :context, :refresh_persisted_tags, :on_change
76
+ attr_accessor :context, :tags_association, :on_change
77
+
78
+ def respond_to_missing?(name, _include_private = false)
79
+ tags.respond_to?(name)
80
+ end
81
+
82
+ def method_missing(name, *args, &block)
83
+ return super unless respond_to_missing?(name)
84
+
85
+ tags.send(name, *args, &block)
86
+ end
87
+
88
+ def notify_change
89
+ on_change.call(self) if changed?
90
+ end
91
+
92
+ def preloaded_persisted_tags
93
+ return TagList.new(tags_association.reload.map(&:name)) if @preloaded
94
+
95
+ @preloaded = true
96
+ TagList.new(tags_association.map(&:name))
97
+ end
55
98
  end
56
99
  end
@@ -33,7 +33,7 @@ module EasyTags
33
33
  attribute :#{context}_list, ActiveModel::Type::Value.new
34
34
 
35
35
  def #{context}
36
- _taggable_context(:#{context}).tags
36
+ _taggable_context(:#{context})
37
37
  end
38
38
 
39
39
  def #{context}=(value)
@@ -49,6 +49,10 @@ module EasyTags
49
49
  _taggable_context(:#{context}).update(value)
50
50
  #{context}_list
51
51
  end
52
+
53
+ def #{context}_list_persisted
54
+ _taggable_context(:#{context}).persisted_tags.to_s
55
+ end
52
56
  RUBY
53
57
  end
54
58
  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
- 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.1.0'.freeze
2
+ VERSION = '0.2.4'.freeze
3
3
  end
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.1.0
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iwo Dziechciarow
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-15 00:00:00.000000000 Z
11
+ date: 2020-06-08 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
@@ -150,6 +176,7 @@ files:
150
176
  - ".travis.yml"
151
177
  - ".yardopts"
152
178
  - Appraisals
179
+ - CHANGELOG.md
153
180
  - Gemfile
154
181
  - LICENSE.txt
155
182
  - MIGRATING_FROM_AATO.MD
@@ -158,10 +185,11 @@ files:
158
185
  - bin/console
159
186
  - bin/setup
160
187
  - easy_tags.gemspec
161
- - gemfiles/activerecord_5.0.gemfile
162
188
  - gemfiles/activerecord_5.1.gemfile
163
189
  - gemfiles/activerecord_5.2.gemfile
190
+ - gemfiles/activerecord_6.0.gemfile
164
191
  - lib/easy_tags.rb
192
+ - lib/easy_tags/dirty_methods.rb
165
193
  - lib/easy_tags/generators/default.rb
166
194
  - lib/easy_tags/options/callback.rb
167
195
  - lib/easy_tags/options/collection.rb
@@ -180,7 +208,11 @@ files:
180
208
  homepage: https://github.com/iiwo/easy_tags
181
209
  licenses:
182
210
  - MIT
183
- metadata: {}
211
+ metadata:
212
+ homepage_uri: https://github.com/iiwo/easy_tags
213
+ changelog_uri: https://github.com/iiwo/easy_tags/blob/master/CHANGELOG.md
214
+ source_code_uri: https://github.com/iiwo/easy_tags
215
+ bug_tracker_uri: https://github.com/iiwo/easy_tags/issues
184
216
  post_install_message:
185
217
  rdoc_options: []
186
218
  require_paths:
@@ -196,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
228
  - !ruby/object:Gem::Version
197
229
  version: '0'
198
230
  requirements: []
199
- rubygems_version: 3.0.4
231
+ rubygems_version: 3.0.8
200
232
  signing_key:
201
233
  specification_version: 4
202
234
  summary: EasyTags allows you to tag a single model on several contexts
@@ -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: '../'