make_taggable 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +47 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +3 -0
  5. data/.standard.yml +18 -0
  6. data/.standard_todo.yml +5 -0
  7. data/.travis.yml +36 -0
  8. data/Appraisals +11 -0
  9. data/CHANGELOG.md +0 -0
  10. data/CODE_OF_CONDUCT.md +74 -0
  11. data/CONTRIBUTING.md +57 -0
  12. data/Gemfile +16 -0
  13. data/LICENSE.md +20 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +478 -0
  16. data/Rakefile +7 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/db/migrate/1_create_make_taggable_tags.rb +10 -0
  20. data/db/migrate/2_create_make_taggable_taggings.rb +12 -0
  21. data/db/migrate/3_add_index_to_tags.rb +5 -0
  22. data/db/migrate/4_add_index_to_taggings.rb +12 -0
  23. data/gemfiles/rails_5.gemfile +9 -0
  24. data/gemfiles/rails_6.gemfile +9 -0
  25. data/gemfiles/rails_master.gemfile +9 -0
  26. data/lib/make_taggable.rb +134 -0
  27. data/lib/make_taggable/default_parser.rb +75 -0
  28. data/lib/make_taggable/engine.rb +4 -0
  29. data/lib/make_taggable/generic_parser.rb +19 -0
  30. data/lib/make_taggable/tag.rb +131 -0
  31. data/lib/make_taggable/tag_list.rb +102 -0
  32. data/lib/make_taggable/taggable.rb +100 -0
  33. data/lib/make_taggable/taggable/cache.rb +90 -0
  34. data/lib/make_taggable/taggable/collection.rb +183 -0
  35. data/lib/make_taggable/taggable/core.rb +323 -0
  36. data/lib/make_taggable/taggable/ownership.rb +137 -0
  37. data/lib/make_taggable/taggable/related.rb +71 -0
  38. data/lib/make_taggable/taggable/tag_list_type.rb +4 -0
  39. data/lib/make_taggable/taggable/tagged_with_query.rb +16 -0
  40. data/lib/make_taggable/taggable/tagged_with_query/all_tags_query.rb +111 -0
  41. data/lib/make_taggable/taggable/tagged_with_query/any_tags_query.rb +68 -0
  42. data/lib/make_taggable/taggable/tagged_with_query/exclude_tags_query.rb +81 -0
  43. data/lib/make_taggable/taggable/tagged_with_query/query_base.rb +61 -0
  44. data/lib/make_taggable/tagger.rb +89 -0
  45. data/lib/make_taggable/tagging.rb +32 -0
  46. data/lib/make_taggable/tags_helper.rb +15 -0
  47. data/lib/make_taggable/utils.rb +34 -0
  48. data/lib/make_taggable/version.rb +4 -0
  49. data/lib/tasks/tags_collate_utf8.rake +17 -0
  50. data/make_taggable.gemspec +26 -0
  51. data/spec/dummy/README.md +24 -0
  52. data/spec/dummy/Rakefile +6 -0
  53. data/spec/dummy/app/assets/config/manifest.js +2 -0
  54. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  55. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  56. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  57. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  58. data/spec/dummy/app/jobs/application_job.rb +7 -0
  59. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  60. data/spec/dummy/app/models/altered_inheriting_taggable_model.rb +5 -0
  61. data/spec/dummy/app/models/application_record.rb +3 -0
  62. data/spec/dummy/app/models/cached_model.rb +3 -0
  63. data/spec/dummy/app/models/cached_model_with_array.rb +11 -0
  64. data/spec/dummy/app/models/columns_override_model.rb +5 -0
  65. data/spec/dummy/app/models/company.rb +15 -0
  66. data/spec/dummy/app/models/concerns/.keep +0 -0
  67. data/spec/dummy/app/models/inheriting_taggable_model.rb +4 -0
  68. data/spec/dummy/app/models/market.rb +2 -0
  69. data/spec/dummy/app/models/non_standard_id_taggable_model.rb +8 -0
  70. data/spec/dummy/app/models/ordered_taggable_model.rb +4 -0
  71. data/spec/dummy/app/models/other_cached_model.rb +3 -0
  72. data/spec/dummy/app/models/other_taggable_model.rb +4 -0
  73. data/spec/dummy/app/models/student.rb +4 -0
  74. data/spec/dummy/app/models/taggable_model.rb +14 -0
  75. data/spec/dummy/app/models/untaggable_model.rb +3 -0
  76. data/spec/dummy/app/models/user.rb +3 -0
  77. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  78. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  79. data/spec/dummy/bin/rails +4 -0
  80. data/spec/dummy/bin/rake +4 -0
  81. data/spec/dummy/bin/setup +33 -0
  82. data/spec/dummy/config.ru +5 -0
  83. data/spec/dummy/config/application.rb +19 -0
  84. data/spec/dummy/config/boot.rb +5 -0
  85. data/spec/dummy/config/cable.yml +10 -0
  86. data/spec/dummy/config/credentials.yml.enc +1 -0
  87. data/spec/dummy/config/database.yml +25 -0
  88. data/spec/dummy/config/environment.rb +5 -0
  89. data/spec/dummy/config/environments/development.rb +52 -0
  90. data/spec/dummy/config/environments/production.rb +105 -0
  91. data/spec/dummy/config/environments/test.rb +49 -0
  92. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  93. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  94. data/spec/dummy/config/initializers/cors.rb +16 -0
  95. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  96. data/spec/dummy/config/initializers/inflections.rb +16 -0
  97. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +33 -0
  100. data/spec/dummy/config/master.key +1 -0
  101. data/spec/dummy/config/puma.rb +38 -0
  102. data/spec/dummy/config/routes.rb +3 -0
  103. data/spec/dummy/config/spring.rb +6 -0
  104. data/spec/dummy/config/storage.yml +34 -0
  105. data/spec/dummy/db/migrate/20201119220853_create_taggable_models.rb +8 -0
  106. data/spec/dummy/db/migrate/20201119221037_create_columns_override_models.rb +9 -0
  107. data/spec/dummy/db/migrate/20201119221121_create_non_standard_id_taggable_models.rb +8 -0
  108. data/spec/dummy/db/migrate/20201119221228_create_untaggable_models.rb +8 -0
  109. data/spec/dummy/db/migrate/20201119221247_create_cached_models.rb +9 -0
  110. data/spec/dummy/db/migrate/20201119221314_create_other_cached_models.rb +11 -0
  111. data/spec/dummy/db/migrate/20201119221343_create_companies.rb +7 -0
  112. data/spec/dummy/db/migrate/20201119221416_create_users.rb +7 -0
  113. data/spec/dummy/db/migrate/20201119221434_create_other_taggable_models.rb +8 -0
  114. data/spec/dummy/db/migrate/20201119221507_create_ordered_taggable_models.rb +8 -0
  115. data/spec/dummy/db/migrate/20201119221530_create_cache_methods_injected_models.rb +7 -0
  116. data/spec/dummy/db/migrate/20201119221629_create_other_cached_with_array_models.rb +11 -0
  117. data/spec/dummy/db/migrate/20201119221746_create_taggable_model_with_jsons.rb +9 -0
  118. data/spec/dummy/db/migrate/20201119222429_create_make_taggable_tags.make_taggable_engine.rb +11 -0
  119. data/spec/dummy/db/migrate/20201119222430_create_make_taggable_taggings.make_taggable_engine.rb +13 -0
  120. data/spec/dummy/db/migrate/20201119222431_add_index_to_tags.make_taggable_engine.rb +6 -0
  121. data/spec/dummy/db/migrate/20201119222432_add_index_to_taggings.make_taggable_engine.rb +13 -0
  122. data/spec/dummy/db/schema.rb +117 -0
  123. data/spec/dummy/db/seeds.rb +7 -0
  124. data/spec/dummy/lib/tasks/.keep +0 -0
  125. data/spec/dummy/log/.keep +0 -0
  126. data/spec/dummy/public/robots.txt +1 -0
  127. data/spec/dummy/storage/.keep +0 -0
  128. data/spec/dummy/test/channels/application_cable/connection_test.rb +11 -0
  129. data/spec/dummy/test/controllers/.keep +0 -0
  130. data/spec/dummy/test/fixtures/.keep +0 -0
  131. data/spec/dummy/test/fixtures/files/.keep +0 -0
  132. data/spec/dummy/test/integration/.keep +0 -0
  133. data/spec/dummy/test/mailers/.keep +0 -0
  134. data/spec/dummy/test/models/.keep +0 -0
  135. data/spec/dummy/test/test_helper.rb +13 -0
  136. data/spec/dummy/vendor/.keep +0 -0
  137. data/spec/make_taggable/acts_as_tagger_spec.rb +112 -0
  138. data/spec/make_taggable/caching_spec.rb +123 -0
  139. data/spec/make_taggable/default_parser_spec.rb +45 -0
  140. data/spec/make_taggable/dirty_spec.rb +140 -0
  141. data/spec/make_taggable/generic_parser_spec.rb +13 -0
  142. data/spec/make_taggable/make_taggable_spec.rb +260 -0
  143. data/spec/make_taggable/related_spec.rb +93 -0
  144. data/spec/make_taggable/single_table_inheritance_spec.rb +220 -0
  145. data/spec/make_taggable/tag_list_spec.rb +169 -0
  146. data/spec/make_taggable/tag_spec.rb +297 -0
  147. data/spec/make_taggable/taggable_spec.rb +804 -0
  148. data/spec/make_taggable/tagger_spec.rb +149 -0
  149. data/spec/make_taggable/tagging_spec.rb +115 -0
  150. data/spec/make_taggable/tags_helper_spec.rb +43 -0
  151. data/spec/make_taggable/utils_spec.rb +22 -0
  152. data/spec/make_taggable_spec.rb +5 -0
  153. data/spec/spec_helper.rb +18 -0
  154. data/spec/support/array.rb +9 -0
  155. data/spec/support/helpers.rb +31 -0
  156. metadata +391 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 75e4c687d801738a1e36a15accd18686dd13ed883941e609bbfae23f98eaaae9
4
+ data.tar.gz: 103971ae8293cbfaaf351c3193022332eb024581c02ca89ea1d95d8bb8a4f154
5
+ SHA512:
6
+ metadata.gz: eaf416b1f1490f92bf44c1992bbf68519a44ef55068f4183c73fbb19f729d4864e89124a4454e65afe9e164e16c9339f3659ae4d6ed95821ddfd15371649de3d
7
+ data.tar.gz: 46b07f4697367374b69458d011b6770883ae36b29c519c66dedd1aa070ca22cb08defecc8d80da29d79860a82368592898ba3be5a77d7b33e308f5a4c2d630f3
@@ -0,0 +1,47 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - '*'
7
+ push:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby: [ '2.7', '2.6', '2.5' ]
16
+ steps:
17
+ - uses: actions/checkout@master
18
+
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+
24
+ - name: Cache gems
25
+ uses: actions/cache@v1
26
+ with:
27
+ path: vendor/bundle
28
+ key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
29
+ restore-keys: |
30
+ ${{ runner.os }}-gem-
31
+ - name: Install dependencies
32
+ run: |
33
+ sudo apt-get update
34
+ sudo apt-get install libsqlite3-dev
35
+ gem update --system
36
+ gem install bundler
37
+ bundle install --jobs 4 --retry 3
38
+ bundle exec appraisal install
39
+
40
+ - name: StandardRb check
41
+ run: bundle exec standardrb
42
+
43
+ - name: Run tests
44
+ env:
45
+ RAILS_ENV: test
46
+ run: |
47
+ bundle exec appraisal rake
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.log
2
+ *.sqlite3
3
+ /pkg/*
4
+ .bundle
5
+ .ruby-version
6
+ spec/internal/config/database.yml
7
+ tmp*.sw?
8
+ *.sw?
9
+ tmp
10
+ *.gem
11
+ *.lock
12
+ *.iml
13
+ /.idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,18 @@
1
+ # Auto generated files with errors to ignore.
2
+ # Remove from this list as you refactor files.
3
+ ---
4
+ ignore:
5
+ - spec/dummy/Rakefile
6
+ - spec/dummy/app/mailers/application_mailer.rb
7
+ - spec/dummy/bin/rails
8
+ - spec/dummy/bin/rake
9
+ - spec/dummy/bin/setup
10
+ - spec/dummy/config.ru
11
+ - spec/dummy/config/application.rb
12
+ - spec/dummy/config/environment.rb
13
+ - spec/dummy/config/environments/development.rb
14
+ - spec/dummy/config/environments/production.rb
15
+ - spec/dummy/config/environments/test.rb
16
+ - spec/dummy/config/puma.rb
17
+ - spec/dummy/db/schema.rb
18
+ - spec/dummy/test/test_helper.rb
@@ -0,0 +1,5 @@
1
+ # Auto generated files with errors to ignore.
2
+ # Remove from this list as you refactor files.
3
+ ---
4
+ ignore:
5
+ - spec/make_taggable/caching_spec.rb
data/.travis.yml ADDED
@@ -0,0 +1,36 @@
1
+ ---
2
+ os: linux
3
+ dist: bionic
4
+ language: ruby
5
+ cache: bundler
6
+
7
+ services:
8
+ - mysql
9
+ - postgresql
10
+
11
+ rvm:
12
+ - 2.7
13
+ - 2.6
14
+ - 2.5
15
+
16
+ env:
17
+ - DB=sqlite3
18
+ - DB=mysql
19
+ - DB=postgresql
20
+
21
+ gemfile:
22
+ - gemfiles/rails_5.gemfile
23
+ - gemfiles/rails_6.gemfile
24
+ - gemfiles/rails_master.gemfile
25
+
26
+ bundler_args: '--without local_development --jobs 3 --retry 3'
27
+
28
+ before_install:
29
+ - gem update bundler
30
+
31
+ script: bundle exec rake
32
+
33
+ jobs:
34
+ allow_failures:
35
+ - rvm: ruby-head
36
+ fast_finish: true
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "rails-5" do
2
+ gem "rails", "~> 5.2.0"
3
+ end
4
+
5
+ appraise "rails-6" do
6
+ gem "rails", "~> 6.0.0"
7
+ end
8
+
9
+ appraise "rails-master" do
10
+ gem "rails", github: "rails/rails"
11
+ end
data/CHANGELOG.md ADDED
File without changes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at m.kennedy@me.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,57 @@
1
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
+ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4
+
5
+ - [How to contribute:](#how-to-contribute)
6
+ - [Bug reports / Issues](#bug-reports--issues)
7
+ - [Code](#code)
8
+ - [Commit Messages](#commit-messages)
9
+ - [About Pull Requests (PR's)](#about-pull-requests-prs)
10
+ - [Documentation](#documentation)
11
+
12
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
13
+
14
+ # How to contribute:
15
+
16
+ ## Bug reports / Issues
17
+
18
+ * Is something broken or not working as expected? Check for an existing issue or [create a new one](https://github.com/mbleigh/acts-as-taggable-on/issues/new)
19
+ * IMPORTANT: Include the version of the gem, if you've install from git, what Ruby and Rails you are running, etc.
20
+
21
+ ## Code
22
+
23
+ 1. [Fork and clone the repo](https://help.github.com/articles/fork-a-repo)
24
+ 2. Install the gem dependencies: `bundle install`
25
+ 3. Make the changes you want and back them up with tests.
26
+ * [Run the tests](https://github.com/mbleigh/acts-as-taggable-on#testing) (`bundle exec rake spec`)
27
+ 4. Update the CHANGELOG.md file with your changes and give yourself credit
28
+ 5. Commit and create a pull request with details as to what has been changed and why
29
+ * Use well-described, small (atomic) commits.
30
+ * Include links to any relevant github issues.
31
+ * *Don't* change the VERSION file.
32
+ 6. Extra Credit: [Confirm it runs and tests pass on the rubies specified in the travis config](.travis.yml). I will otherwise confirm it runs on these.
33
+
34
+ How I handle pull requests:
35
+
36
+ * If the tests pass and the pull request looks good, I will merge it.
37
+ * If the pull request needs to be changed,
38
+ * you can change it by updating the branch you generated the pull request from
39
+ * either by adding more commits, or
40
+ * by force pushing to it
41
+ * I can make any changes myself and manually merge the code in.
42
+
43
+ ### Commit Messages
44
+
45
+ * [A Note About Git Commit Messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
46
+ * [http://stopwritingramblingcommitmessages.com/](http://stopwritingramblingcommitmessages.com/)
47
+ * [ThoughtBot style guide](https://github.com/thoughtbot/guides/tree/master/style#git)
48
+
49
+ ### About Pull Requests (PR's)
50
+
51
+ * [All Your Open Source Code Are Belong To Us](http://www.benjaminfleischer.com/2013/07/30/all-your-open-source-code-are-belong-to-us/)
52
+ * [Using Pull Requests](https://help.github.com/articles/using-pull-requests)
53
+ * [Github pull requests made easy](http://www.element84.com/github-pull-requests-made-easy.html)
54
+
55
+ ## Documentation
56
+
57
+ * Update the wiki
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in noticed.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # To use a debugger
15
+ gem "byebug", group: [:development, :test]
16
+ gem "listen", group: [:development, :test]
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ __Copyright (c) 2020 Matthew Kennedy.__
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Matthew Kennedy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,478 @@
1
+ # MakeTaggable
2
+ [![Gem Version](https://badge.fury.io/rb/make_taggable.svg)](https://badge.fury.io/rb/make_taggable)
3
+ [![Build Status](https://travis-ci.com/MatthewKennedy/make_taggable.svg?branch=master)](https://travis-ci.com/MatthewKennedy/make_taggable)
4
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
5
+
6
+ MakeTaggable is a fork of acts-as-taggable-on v6.5 with code updates and a new set of migrations. All credit goes to those who contributed before acts-as-taggable-on became MakeTaggable: Michael Bleigh & Joost Baaij.
7
+
8
+ Why fork acts-as-taggable-on? Act As Taggable On appears stuck with a set of legacy migrations from rails pre [4.2] that added and removed indexes so much that the migrations do not run on a fresh install using MySQL.
9
+
10
+ For the PostgreSQL users, this is not an issue, but if you have an app or gem that used acts-as-taggable-on, you can no longer test against MySQL, so it seems a fresh start would be useful to clear out any legacy issues and move forward.
11
+
12
+ ## Installation
13
+
14
+ To use it, add it to your Gemfile:
15
+
16
+ ```ruby
17
+ gem "make_taggable", "~> 0.6.0"
18
+ ```
19
+
20
+ and bundle:
21
+
22
+ ```shell
23
+ bundle
24
+ ```
25
+
26
+ #### Post Installation
27
+
28
+ Install migrations
29
+
30
+ ```shell
31
+ # For the latest versions :
32
+ rails make_taggable_engine:install:migrations
33
+ ```
34
+
35
+ Review the generated migrations then migrate :
36
+ ```shell
37
+ rails db:migrate
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ Setup
43
+
44
+ ```ruby
45
+ class User < ActiveRecord::Base
46
+ make_taggable # Alias for make_taggable :tags
47
+ make_taggable :skills, :interests
48
+ end
49
+
50
+ class UsersController < ApplicationController
51
+ def user_params
52
+ params.require(:user).permit(:name, :tag_list) ## Rails 4 strong params usage
53
+ end
54
+ end
55
+
56
+ @user = User.new(:name => "Bobby")
57
+ ```
58
+
59
+ Add and remove a single tag
60
+
61
+ ```ruby
62
+ @user.tag_list.add("awesome") # add a single tag. alias for <<
63
+ @user.tag_list.remove("awesome") # remove a single tag
64
+ @user.save # save to persist tag_list
65
+ ```
66
+
67
+ Add and remove multiple tags in an array
68
+
69
+ ```ruby
70
+ @user.tag_list.add("awesome", "slick")
71
+ @user.tag_list.remove("awesome", "slick")
72
+ @user.save
73
+ ```
74
+
75
+ You can also add and remove tags in format of String. This would
76
+ be convenient in some cases such as handling tag input param in a String.
77
+
78
+ Pay attention you need to add `parse: true` as option in this case.
79
+
80
+ You may also want to take a look at delimiter in the string. The default
81
+ is comma `,` so you don't need to do anything here. However, if you made
82
+ a change on delimiter setting, make sure the string will match. See
83
+ [configuration](#configuration) for more about delimiter.
84
+
85
+ ```ruby
86
+ @user.tag_list.add("awesome, slick", parse: true)
87
+ @user.tag_list.remove("awesome, slick", parse: true)
88
+ ```
89
+
90
+ You can also add and remove tags by direct assignment. Note this will
91
+ remove existing tags so use it with attention.
92
+
93
+ ```ruby
94
+ @user.tag_list = "awesome, slick, hefty"
95
+ @user.save
96
+ @user.reload
97
+ @user.tags
98
+ => [#<MakeTaggable::Tag id: 1, name: "awesome", taggings_count: 1>,
99
+ #<MakeTaggable::Tag id: 2, name: "slick", taggings_count: 1>,
100
+ #<MakeTaggable::Tag id: 3, name: "hefty", taggings_count: 1>]
101
+ ```
102
+
103
+ With the defined context in model, you have multiple new methods at disposal
104
+ to manage and view the tags in the context. For example, with `:skill` context
105
+ these methods are added to the model: `skill_list`(and `skill_list.add`, `skill_list.remove`
106
+ `skill_list=`), `skills`(plural), `skill_counts`.
107
+
108
+ ```ruby
109
+ @user.skill_list = "joking, clowning, boxing"
110
+ @user.save
111
+ @user.reload
112
+ @user.skills
113
+ => [#<MakeTaggable::Tag id: 1, name: "joking", taggings_count: 1>,
114
+ #<MakeTaggable::Tag id: 2, name: "clowning", taggings_count: 1>,
115
+ #<MakeTaggable::Tag id: 3, name: "boxing", taggings_count: 1>]
116
+
117
+ @user.skill_list.add("coding")
118
+
119
+ @user.skill_list
120
+ # => ["joking", "clowning", "boxing", "coding"]
121
+
122
+ @another_user = User.new(:name => "Alice")
123
+ @another_user.skill_list.add("clowning")
124
+ @another_user.save
125
+
126
+ User.skill_counts
127
+ => [#<MakeTaggable::Tag id: 1, name: "joking", taggings_count: 1>,
128
+ #<MakeTaggable::Tag id: 2, name: "clowning", taggings_count: 2>,
129
+ #<MakeTaggable::Tag id: 3, name: "boxing", taggings_count: 1>]
130
+ ```
131
+
132
+ To preserve the order in which tags are created use `acts_as_ordered_taggable`:
133
+
134
+ ```ruby
135
+ class User < ActiveRecord::Base
136
+ # Alias for acts_as_ordered_taggable_on :tags
137
+ acts_as_ordered_taggable
138
+ acts_as_ordered_taggable_on :skills, :interests
139
+ end
140
+
141
+ @user = User.new(:name => "Bobby")
142
+ @user.tag_list = "east, south"
143
+ @user.save
144
+
145
+ @user.tag_list = "north, east, south, west"
146
+ @user.save
147
+
148
+ @user.reload
149
+ @user.tag_list # => ["north", "east", "south", "west"]
150
+ ```
151
+
152
+ ### Finding most or least used tags
153
+
154
+ You can find the most or least used tags by using:
155
+
156
+ ```ruby
157
+ MakeTaggable::Tag.most_used
158
+ MakeTaggable::Tag.least_used
159
+ ```
160
+
161
+ You can also filter the results by passing the method a limit, however the default limit is 20.
162
+
163
+ ```ruby
164
+ MakeTaggable::Tag.most_used(10)
165
+ MakeTaggable::Tag.least_used(10)
166
+ ```
167
+
168
+ ### Finding Tagged Objects
169
+
170
+ Make Taggable uses scopes to create an association for tags.
171
+ This way you can mix and match to filter down your results.
172
+
173
+ ```ruby
174
+ class User < ActiveRecord::Base
175
+ make_taggable :tags, :skills
176
+ scope :by_join_date, order("created_at DESC")
177
+ end
178
+
179
+ User.tagged_with("awesome").by_join_date
180
+ User.tagged_with("awesome").by_join_date.paginate(:page => params[:page], :per_page => 20)
181
+
182
+ # Find users that matches all given tags:
183
+ # NOTE: This only matches users that have the exact set of specified tags. If a user has additional tags, they are not returned.
184
+ User.tagged_with(["awesome", "cool"], :match_all => true)
185
+
186
+ # Find users with any of the specified tags:
187
+ User.tagged_with(["awesome", "cool"], :any => true)
188
+
189
+ # Find users that have not been tagged with awesome or cool:
190
+ User.tagged_with(["awesome", "cool"], :exclude => true)
191
+
192
+ # Find users with any of the tags based on context:
193
+ User.tagged_with(['awesome', 'cool'], :on => :tags, :any => true).tagged_with(['smart', 'shy'], :on => :skills, :any => true)
194
+ ```
195
+
196
+ You can also use `:wild => true` option along with `:any` or `:exclude` option. It will be looking for `%awesome%` and `%cool%` in SQL.
197
+
198
+ __Tip:__ `User.tagged_with([])` or `User.tagged_with('')` will return `[]`, an empty set of records.
199
+
200
+
201
+ ### Relationships
202
+
203
+ You can find objects of the same type based on similar tags on certain contexts.
204
+ Also, objects will be returned in descending order based on the total number of
205
+ matched tags.
206
+
207
+ ```ruby
208
+ @bobby = User.find_by_name("Bobby")
209
+ @bobby.skill_list # => ["jogging", "diving"]
210
+
211
+ @frankie = User.find_by_name("Frankie")
212
+ @frankie.skill_list # => ["hacking"]
213
+
214
+ @tom = User.find_by_name("Tom")
215
+ @tom.skill_list # => ["hacking", "jogging", "diving"]
216
+
217
+ @tom.find_related_skills # => [<User name="Bobby">, <User name="Frankie">]
218
+ @bobby.find_related_skills # => [<User name="Tom">]
219
+ @frankie.find_related_skills # => [<User name="Tom">]
220
+ ```
221
+
222
+ ### Dynamic Tag Contexts
223
+
224
+ In addition to the generated tag contexts in the definition, it is also possible
225
+ to allow for dynamic tag contexts (this could be user generated tag contexts!)
226
+
227
+ ```ruby
228
+ @user = User.new(:name => "Bobby")
229
+ @user.set_tag_list_on(:customs, "same, as, tag, list")
230
+ @user.tag_list_on(:customs) # => ["same", "as", "tag", "list"]
231
+ @user.save
232
+ @user.tags_on(:customs) # => [<Tag name='same'>,...]
233
+ @user.tag_counts_on(:customs)
234
+ User.tagged_with("same", :on => :customs) # => [@user]
235
+ ```
236
+
237
+ ### Tag Parsers
238
+
239
+ If you want to change how tags are parsed, you can define your own implementation:
240
+
241
+ ```ruby
242
+ class MyParser < MakeTaggable::GenericParser
243
+ def parse
244
+ MakeTaggable::TagList.new.tap do |tag_list|
245
+ tag_list.add @tag_list.split('|')
246
+ end
247
+ end
248
+ end
249
+ ```
250
+
251
+ Now you can use this parser, passing it as parameter:
252
+
253
+ ```ruby
254
+ @user = User.new(:name => "Bobby")
255
+ @user.tag_list = "east, south"
256
+ @user.tag_list.add("north|west", parser: MyParser)
257
+ @user.tag_list # => ["north", "east", "south", "west"]
258
+
259
+ # Or also:
260
+ @user.tag_list.parser = MyParser
261
+ @user.tag_list.add("north|west")
262
+ @user.tag_list # => ["north", "east", "south", "west"]
263
+ ```
264
+
265
+ Or change it globally:
266
+
267
+ ```ruby
268
+ MakeTaggable.default_parser = MyParser
269
+ @user = User.new(:name => "Bobby")
270
+ @user.tag_list = "east|south"
271
+ @user.tag_list # => ["east", "south"]
272
+ ```
273
+
274
+ ### Tag Ownership
275
+
276
+ Tags can have owners:
277
+
278
+ ```ruby
279
+ class User < ActiveRecord::Base
280
+ acts_as_tagger
281
+ end
282
+
283
+ class Photo < ActiveRecord::Base
284
+ make_taggable :locations
285
+ end
286
+
287
+ @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
288
+ @some_user.owned_taggings
289
+ @some_user.owned_tags
290
+ Photo.tagged_with("paris", :on => :locations, :owned_by => @some_user)
291
+ @some_photo.locations_from(@some_user) # => ["paris", "normandy"]
292
+ @some_photo.owner_tags_on(@some_user, :locations) # => [#<MakeTaggable::Tag id: 1, name: "paris">...]
293
+ @some_photo.owner_tags_on(nil, :locations) # => Ownerships equivalent to saying @some_photo.locations
294
+ @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object
295
+ ```
296
+
297
+ #### Working with Owned Tags
298
+ Note that `tag_list` only returns tags whose taggings do not have an owner. Continuing from the above example:
299
+ ```ruby
300
+ @some_photo.tag_list # => []
301
+ ```
302
+ To retrieve all tags of an object (regardless of ownership) or if only one owner can tag the object, use `all_tags_list`.
303
+
304
+ ##### Adding owned tags
305
+ Note that **owned tags** are added all at once, in the form of ***comma seperated tags*** in string.
306
+ Also, when you try to add **owned tags** again, it simply overwrites the previous set of **owned tags**.
307
+ So to append tags in previously existing **owned tags** list, go as follows:
308
+ ```ruby
309
+ def add_owned_tag
310
+ @some_item = Item.find(params[:id])
311
+ owned_tag_list = @some_item.all_tags_list - @some_item.tag_list
312
+ owned_tag_list += [(params[:tag])]
313
+ @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
314
+ @some_item.save
315
+ end
316
+
317
+ def stringify(tag_list)
318
+ tag_list.inject('') { |memo, tag| memo += (tag + ',') }[0..-1]
319
+ end
320
+ ```
321
+ ##### Removing owned tags
322
+ Similarly as above, removing will be as follows:
323
+ ```ruby
324
+ def remove_owned_tag
325
+ @some_item = Item.find(params[:id])
326
+ owned_tag_list = @some_item.all_tags_list - @some_item.tag_list
327
+ owned_tag_list -= [(params[:tag])]
328
+ @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
329
+ @some_item.save
330
+ end
331
+ ```
332
+
333
+ ### Dirty objects
334
+
335
+ ```ruby
336
+ @bobby = User.find_by_name("Bobby")
337
+ @bobby.skill_list # => ["jogging", "diving"]
338
+
339
+ @bobby.skill_list_changed? #=> false
340
+ @bobby.changes #=> {}
341
+
342
+ @bobby.skill_list = "swimming"
343
+ @bobby.changes.should == {"skill_list"=>["jogging, diving", ["swimming"]]}
344
+ @bobby.skill_list_changed? #=> true
345
+
346
+ @bobby.skill_list_change.should == ["jogging, diving", ["swimming"]]
347
+ ```
348
+
349
+ ### Tag cloud calculations
350
+
351
+ To construct tag clouds, the frequency of each tag needs to be calculated.
352
+ Because we specified `make_taggable` on the `User` class, we can
353
+ get a calculation of all the tag counts by using `User.tag_counts_on(:customs)`. But what if we wanted a tag count for
354
+ a single user's posts? To achieve this we call tag_counts on the association:
355
+
356
+ ```ruby
357
+ User.find(:first).posts.tag_counts_on(:tags)
358
+ ```
359
+
360
+ A helper is included to assist with generating tag clouds.
361
+
362
+ Here is an example that generates a tag cloud.
363
+
364
+ Helper:
365
+
366
+ ```ruby
367
+ module PostsHelper
368
+ include MakeTaggable::TagsHelper
369
+ end
370
+ ```
371
+
372
+ Controller:
373
+
374
+ ```ruby
375
+ class PostController < ApplicationController
376
+ def tag_cloud
377
+ @tags = Post.tag_counts_on(:tags)
378
+ end
379
+ end
380
+ ```
381
+
382
+ View:
383
+
384
+ ```erb
385
+ <% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
386
+ <%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
387
+ <% end %>
388
+ ```
389
+
390
+ CSS:
391
+
392
+ ```css
393
+ .css1 { font-size: 1.0em; }
394
+ .css2 { font-size: 1.2em; }
395
+ .css3 { font-size: 1.4em; }
396
+ .css4 { font-size: 1.6em; }
397
+ ```
398
+
399
+ ## Configuration
400
+
401
+ If you would like to remove unused tag objects after removing taggings, add:
402
+
403
+ ```ruby
404
+ MakeTaggable.remove_unused_tags = true
405
+ ```
406
+
407
+ If you want force tags to be saved downcased:
408
+
409
+ ```ruby
410
+ MakeTaggable.force_lowercase = true
411
+ ```
412
+
413
+ If you want tags to be saved parametrized (you can redefine to_param as well):
414
+
415
+ ```ruby
416
+ MakeTaggable.force_parameterize = true
417
+ ```
418
+
419
+ If you would like tags to be case-sensitive and not use LIKE queries for creation:
420
+
421
+ ```ruby
422
+ MakeTaggable.strict_case_match = true
423
+ ```
424
+
425
+ If you would like to have an exact match covering special characters with MySql:
426
+
427
+ ```ruby
428
+ MakeTaggable.force_binary_collation = true
429
+ ```
430
+
431
+ If you would like to specify table names:
432
+
433
+ ```ruby
434
+ MakeTaggable.tags_table = 'aato_tags'
435
+ MakeTaggable.taggings_table = 'aato_taggings'
436
+ ```
437
+
438
+ If you want to change the default delimiter (it defaults to ','). You can also pass in an array of delimiters such as ([',', '|']):
439
+
440
+ ```ruby
441
+ MakeTaggable.delimiter = ','
442
+ ```
443
+
444
+ *NOTE 1: SQLite by default can't upcase or downcase multibyte characters, resulting in unwanted behavior. Load the SQLite ICU extension for proper handle of such characters. [See docs](http://www.sqlite.org/src/artifact?ci=trunk&filename=ext/icu/README.txt)*
445
+
446
+
447
+ #### Upgrading
448
+
449
+ see [UPGRADING](UPGRADING.md)
450
+
451
+ ## Contributors
452
+
453
+ We have a long list of valued contributors. [Check them all](https://github.com/mbleigh/acts-as-taggable-on/contributors)
454
+
455
+ ## Compatibility
456
+
457
+ Versions 0.6.x is compatible with Ruby 2.5 + and Rails 6.
458
+
459
+
460
+ ## TODO
461
+ - Review migrations indexes they seem excessive looking at the schema.
462
+ - See if the newer version of ActiveRecord or arel can be used instead of the MySQL workarounds.
463
+
464
+ ## Testing
465
+
466
+ Make Taggable uses RSpec for its test coverage. Inside the gem
467
+ directory, you can run the specs with:
468
+
469
+ ```shell
470
+ bundle
471
+ rake spec
472
+ ```
473
+
474
+ You can run all the tests across all the Rails versions by running `rake appraise`. If you'd also like to [run the tests across all rubies and databases as configured for Travis CI, install and run `wwtd`](https://github.com/grosser/wwtd).
475
+
476
+
477
+ ## License
478
+ MIT