freeze_tag 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3ffb789a97a168f562d82cbbcbafe9cea792d9c
4
+ data.tar.gz: 74e21ca1f03b52ea295964ccdcba756250423e61
5
+ SHA512:
6
+ metadata.gz: 9ae4657972deba0f249602afd6f1003167e95896b80e76b66933f56f100f71355bd7ff41a141ec72e5aed8d8bd2868be8d1cceee870286015ca43ce31f360b23
7
+ data.tar.gz: 2e20761a2789411d0113e4ca7813b8fd32ced24b15e8c5d741895284a7980aeb74f1a9dc9d977e255a6b2af809bc2d108822b7595ec34573d51682c3b5c27bdf
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.5
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,75 @@
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
+ * Using overtly pedantic language
34
+
35
+ ## Our Responsibilities
36
+
37
+ Project maintainers are responsible for clarifying the standards of acceptable
38
+ behavior and are expected to take appropriate and fair corrective action in
39
+ response to any instances of unacceptable behavior.
40
+
41
+ Project maintainers have the right and responsibility to remove, edit, or
42
+ reject comments, commits, code, wiki edits, issues, and other contributions
43
+ that are not aligned to this Code of Conduct, or to ban temporarily or
44
+ permanently any contributor for other behaviors that they deem inappropriate,
45
+ threatening, offensive, or harmful.
46
+
47
+ ## Scope
48
+
49
+ This Code of Conduct applies both within project spaces and in public spaces
50
+ when an individual is representing the project or its community. Examples of
51
+ representing a project or community include using an official project e-mail
52
+ address, posting via an official social media account, or acting as an appointed
53
+ representative at an online or offline event. Representation of a project may be
54
+ further defined and clarified by project maintainers.
55
+
56
+ ## Enforcement
57
+
58
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
59
+ reported by contacting the project team at paul@wework.com. All
60
+ complaints will be reviewed and investigated and will result in a response that
61
+ is deemed necessary and appropriate to the circumstances. The project team is
62
+ obligated to maintain confidentiality with regard to the reporter of an incident.
63
+ Further details of specific enforcement policies may be posted separately.
64
+
65
+ Project maintainers who do not follow or enforce the Code of Conduct in good
66
+ faith may face temporary or permanent repercussions as determined by other
67
+ members of the project's leadership.
68
+
69
+ ## Attribution
70
+
71
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72
+ available at [http://contributor-covenant.org/version/1/4][version]
73
+
74
+ [homepage]: http://contributor-covenant.org
75
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in freeze_tag.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,174 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ freeze_tag (0.1.0)
5
+ rails (>= 4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.1.6)
11
+ actionpack (= 5.1.6)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (~> 0.6.1)
14
+ actionmailer (5.1.6)
15
+ actionpack (= 5.1.6)
16
+ actionview (= 5.1.6)
17
+ activejob (= 5.1.6)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.1.6)
21
+ actionview (= 5.1.6)
22
+ activesupport (= 5.1.6)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.1.6)
28
+ activesupport (= 5.1.6)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.1.6)
34
+ activesupport (= 5.1.6)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.1.6)
37
+ activesupport (= 5.1.6)
38
+ activerecord (5.1.6)
39
+ activemodel (= 5.1.6)
40
+ activesupport (= 5.1.6)
41
+ arel (~> 8.0)
42
+ activesupport (5.1.6)
43
+ concurrent-ruby (~> 1.0, >= 1.0.2)
44
+ i18n (>= 0.7, < 2)
45
+ minitest (~> 5.1)
46
+ tzinfo (~> 1.1)
47
+ addressable (2.5.2)
48
+ public_suffix (>= 2.0.2, < 4.0)
49
+ appraisal (2.2.0)
50
+ bundler
51
+ rake
52
+ thor (>= 0.14.0)
53
+ arel (8.0.0)
54
+ builder (3.2.3)
55
+ byebug (9.1.0)
56
+ coderay (1.1.2)
57
+ concurrent-ruby (1.0.5)
58
+ crack (0.4.3)
59
+ safe_yaml (~> 1.0.0)
60
+ crass (1.0.3)
61
+ database_cleaner (1.6.2)
62
+ diff-lcs (1.3)
63
+ erubi (1.7.1)
64
+ globalid (0.4.1)
65
+ activesupport (>= 4.2.0)
66
+ hashdiff (0.3.7)
67
+ i18n (1.0.0)
68
+ concurrent-ruby (~> 1.0)
69
+ loofah (2.2.2)
70
+ crass (~> 1.0.2)
71
+ nokogiri (>= 1.5.9)
72
+ mail (2.7.0)
73
+ mini_mime (>= 0.1.1)
74
+ method_source (0.9.0)
75
+ mini_mime (1.0.0)
76
+ mini_portile2 (2.3.0)
77
+ minitest (5.11.3)
78
+ nio4r (2.3.0)
79
+ nokogiri (1.8.2)
80
+ mini_portile2 (~> 2.3.0)
81
+ pry (0.11.3)
82
+ coderay (~> 1.1.0)
83
+ method_source (~> 0.9.0)
84
+ pry-byebug (3.5.1)
85
+ byebug (~> 9.1)
86
+ pry (~> 0.10)
87
+ public_suffix (3.0.2)
88
+ rack (2.0.4)
89
+ rack-test (1.0.0)
90
+ rack (>= 1.0, < 3)
91
+ rails (5.1.6)
92
+ actioncable (= 5.1.6)
93
+ actionmailer (= 5.1.6)
94
+ actionpack (= 5.1.6)
95
+ actionview (= 5.1.6)
96
+ activejob (= 5.1.6)
97
+ activemodel (= 5.1.6)
98
+ activerecord (= 5.1.6)
99
+ activesupport (= 5.1.6)
100
+ bundler (>= 1.3.0)
101
+ railties (= 5.1.6)
102
+ sprockets-rails (>= 2.0.0)
103
+ rails-dom-testing (2.0.3)
104
+ activesupport (>= 4.2.0)
105
+ nokogiri (>= 1.6)
106
+ rails-html-sanitizer (1.0.4)
107
+ loofah (~> 2.2, >= 2.2.2)
108
+ railties (5.1.6)
109
+ actionpack (= 5.1.6)
110
+ activesupport (= 5.1.6)
111
+ method_source
112
+ rake (>= 0.8.7)
113
+ thor (>= 0.18.1, < 2.0)
114
+ rake (10.5.0)
115
+ rspec (3.7.0)
116
+ rspec-core (~> 3.7.0)
117
+ rspec-expectations (~> 3.7.0)
118
+ rspec-mocks (~> 3.7.0)
119
+ rspec-core (3.7.1)
120
+ rspec-support (~> 3.7.0)
121
+ rspec-expectations (3.7.0)
122
+ diff-lcs (>= 1.2.0, < 2.0)
123
+ rspec-support (~> 3.7.0)
124
+ rspec-mocks (3.7.0)
125
+ diff-lcs (>= 1.2.0, < 2.0)
126
+ rspec-support (~> 3.7.0)
127
+ rspec-rails (3.7.2)
128
+ actionpack (>= 3.0)
129
+ activesupport (>= 3.0)
130
+ railties (>= 3.0)
131
+ rspec-core (~> 3.7.0)
132
+ rspec-expectations (~> 3.7.0)
133
+ rspec-mocks (~> 3.7.0)
134
+ rspec-support (~> 3.7.0)
135
+ rspec-support (3.7.1)
136
+ safe_yaml (1.0.4)
137
+ sprockets (3.7.1)
138
+ concurrent-ruby (~> 1.0)
139
+ rack (> 1, < 3)
140
+ sprockets-rails (3.2.1)
141
+ actionpack (>= 4.0)
142
+ activesupport (>= 4.0)
143
+ sprockets (>= 3.0.0)
144
+ sqlite3 (1.3.13)
145
+ thor (0.20.0)
146
+ thread_safe (0.3.6)
147
+ tzinfo (1.2.5)
148
+ thread_safe (~> 0.1)
149
+ webmock (3.3.0)
150
+ addressable (>= 2.3.6)
151
+ crack (>= 0.3.2)
152
+ hashdiff
153
+ websocket-driver (0.6.5)
154
+ websocket-extensions (>= 0.1.0)
155
+ websocket-extensions (0.1.3)
156
+
157
+ PLATFORMS
158
+ ruby
159
+
160
+ DEPENDENCIES
161
+ appraisal
162
+ bundler (~> 1.16)
163
+ byebug (~> 9.0)
164
+ database_cleaner (~> 1.5)
165
+ freeze_tag!
166
+ pry-byebug (~> 3.4)
167
+ rake (~> 10.0)
168
+ rspec (~> 3.6)
169
+ rspec-rails (~> 3.6)
170
+ sqlite3 (~> 1.3)
171
+ webmock
172
+
173
+ BUNDLED WITH
174
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 WeWork Projects
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, sub-license, 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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # FreezeTag
2
+
3
+ Howdy,
4
+
5
+ The de facto tagging library for almost every Ruby on Rails project has been [Acts As Taggable On Gem](https://github.com/mbleigh/acts-as-taggable-on) which provides a simple interface for polymorphic tagging of your models.
6
+
7
+ As excellent and useful as ActsAsTaggable is, this library is attempt to reconcile some shortcomings:
8
+
9
+ 1. Freeze tag allows for a more "stateless" approach to tagging.
10
+
11
+ Tags are never deleted, instead they have an "ended_at" column, which can be updated to make them active or inactive.
12
+
13
+ 2. The associations are more simple.
14
+
15
+ Tags are held in a single table which holds the content of the tag (its name) and the association back to the model instance its attached to.
16
+ This has some advantages including simpler querying, joining, etc., but obviously drawbacks as well.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'freeze_tag'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Create the tables:
31
+
32
+ 1. Run the installer:
33
+
34
+ ```
35
+ $ rails g freeze_tag:install
36
+ ```
37
+
38
+ This adds a migration to create your "freeze_tags" table
39
+
40
+ 2. Confirm your implementation.
41
+
42
+ Since Freeze tags creates a polymorphic association between tags and models, its necessary to confirm the type of primary keys the models in your application use. Open the migration and choose the correct option for you.
43
+
44
+ 3. Run the migration
45
+
46
+ ```
47
+ rake db:migrate
48
+ ```
49
+
50
+ 4. Add:
51
+ ```ruby
52
+ include FreezeTag::Taggable
53
+ ```
54
+ to the top of any model you'd like to start tagging.
55
+
56
+ 5. Case sensitivity, add:
57
+ ```ruby
58
+ def self.freeze_tag_case_sensitive
59
+ true
60
+ end
61
+ ```
62
+ To your model and all tags will be saved as lowercase
63
+
64
+ #### Tagging a record:
65
+
66
+ A single tag:
67
+
68
+ ```ruby
69
+ my_model_instance.freeze_tag(as: "Fancy")
70
+ ```
71
+
72
+ Or apply multiple tags:
73
+
74
+ ```ruby
75
+ my_model_instance.freeze_tag(as: ["Fancy", "Schmancy"])
76
+ ```
77
+
78
+ Or apply multiple tags and expire all other ones:
79
+
80
+ ```ruby
81
+ my_model_instance.freeze_tag(as: ["Fancy", "Schmancy"], expire_others: true)
82
+ ```
83
+
84
+ ##### Tagging a record, with list:
85
+ There may be times you want multiple lists of tags, i.e. users with skills, AND hobbies
86
+
87
+ All the same methods above work, simple pass a list as an argument.
88
+
89
+ ```ruby
90
+ my_model_instance.freeze_tag(as: "Web Design", list: "Skills")
91
+ ```
92
+
93
+ #### Accessing tags:
94
+
95
+ All the current "active" tags as a simple array of strings.
96
+
97
+ ```ruby
98
+ my_model_instance.freeze_tag_list
99
+ ["Happy", "Go", "Lucky"]
100
+ ```
101
+
102
+ All the tags as a simple array of strings.
103
+
104
+ ```ruby
105
+ my_model_instance.freeze_tag_list(only_active: false)
106
+ ["Happy", "Go", "Lucky", "Sad"]
107
+ ```
108
+
109
+ All the tags, in a list, as a simple array of strings.
110
+
111
+ ```ruby
112
+ my_model_instance.freeze_tag_list(list: "Skills")
113
+ ["Web Design", "Illustration"]
114
+ ```
115
+
116
+ Active Record association of all tags
117
+
118
+ ```ruby
119
+ my_model_instance.freeze_tags
120
+ ```
121
+
122
+ Active Record association of all "active" tags
123
+ ```ruby
124
+ my_model_instance.active_freeze_tags
125
+ ```
126
+
127
+ You can change queries to the above to filter by anything.
128
+ ```ruby
129
+ my_model_instance.freeze_tags.where(list: "Skills")
130
+ my_model_instance.active_freeze_tags.where(list: "Skills")
131
+ ```
132
+
133
+ #### Retrieving records that have been tagged:
134
+
135
+ Currently tagged with (only unexpired)
136
+ ```ruby
137
+ MyModel.freeze_tagged(as: "Fancy")
138
+ ```
139
+
140
+ Previously tagged with (only expired)
141
+ ```ruby
142
+ MyModel.previously_freeze_tagged(as: "Fancy")
143
+ ```
144
+
145
+ Ever tagged with (expired and unexpired)
146
+ ```ruby
147
+ MyModel.ever_freeze_tagged(as: "Fancy")
148
+ ```
149
+
150
+ All the above methods work with a "list" argument as well
151
+ ```ruby
152
+ MyModel.ever_freeze_tagged(as: "Fancy", list: "Skills")
153
+ ```
154
+
155
+ #### Accessing the model directly.
156
+
157
+ ```ruby
158
+ FreezeTag::Tag
159
+ ```
160
+
161
+ Will give you direct access to the freeze tags table in a very standard way.
162
+
163
+ ## Contributing
164
+
165
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wework/freeze-tag. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
166
+
167
+ ## License
168
+
169
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
170
+
171
+ ## Code of Conduct
172
+
173
+ Everyone interacting in the FreezeTag project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/freeze_tag/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "freeze_tag"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "freeze_tag/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "freeze_tag"
8
+ spec.version = FreezeTag::VERSION
9
+ spec.authors = ["Paul Franzen"]
10
+ spec.email = ["paul@wework.com"]
11
+
12
+ spec.summary = %q{A stateless tagging library}
13
+ spec.homepage = "https://wework.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "rails", ">= 4.2"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.6"
28
+ spec.add_development_dependency "rspec-rails", "~> 3.6"
29
+ spec.add_development_dependency "byebug", "~> 9.0"
30
+ spec.add_development_dependency "pry-byebug", "~> 3.4"
31
+ spec.add_development_dependency "sqlite3", "~> 1.3"
32
+ spec.add_development_dependency "database_cleaner", "~> 1.5"
33
+ spec.add_development_dependency 'appraisal'
34
+ spec.add_development_dependency 'webmock'
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+ require 'active_record'
3
+
4
+ module FreezeTag
5
+ class Tag < ::ActiveRecord::Base
6
+ self.table_name = "freeze_tags"
7
+ belongs_to :taggable, polymorphic: true
8
+ end
9
+ end
@@ -0,0 +1,77 @@
1
+ require 'rails'
2
+ require 'active_record'
3
+
4
+ module FreezeTag
5
+ module Taggable
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ has_many :freeze_tags, as: :taggable, class_name: "FreezeTag::Tag"
10
+ has_many :active_freeze_tags, -> { where("ended_at IS NULL OR ended_at > ?", DateTime.now) }, as: :taggable, class_name: "FreezeTag::Tag"
11
+
12
+ def freeze_tag(as: [], expire_others: false, list: nil)
13
+ ActiveRecord::Base.transaction do
14
+ as = as.is_a?(String) ? [as] : as
15
+ as = as.map(&:downcase) if self.class.try(:freeze_tag_case_sensitive)
16
+
17
+ if expire_others == true
18
+ active_freeze_tags.where(list: list).where.not(tag: as).update_all(ended_at: DateTime.now)
19
+ end
20
+
21
+ as.each do |t|
22
+ ft = FreezeTag::Tag.find_or_create_by(taggable_type: self.class.name, taggable_id: self.id, tag: t, list: list)
23
+ ft.ended_at = nil
24
+ ft.save! if ft.changed?
25
+ end
26
+ end
27
+ end
28
+
29
+ def freeze_tag_list(list: nil, only_active: true)
30
+ base = only_active ? active_freeze_tags : freeze_tags
31
+ if list.present?
32
+ base = base.where(list: list)
33
+ end
34
+ base.map(&:tag)
35
+ end
36
+
37
+ def expire_freeze_tag(tag: nil, date: nil, list: nil)
38
+ tag = tag.downcase if self.try(:freeze_tag_case_sensitive)
39
+ to_exp = freeze_tags.find_by(tag: tag, list: list)
40
+ return nil unless to_exp.present?
41
+ exp_at = date.present? ? date : DateTime.now
42
+ to_exp.ended_at = exp_at
43
+ to_exp.save
44
+ end
45
+
46
+ end
47
+
48
+ module ClassMethods
49
+ def freeze_tagged(as: nil, list: nil)
50
+ as = as.downcase if self.try(:freeze_tag_case_sensitive)
51
+ if list.present?
52
+ self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.ended_at IS NULL OR freeze_tags.ended_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'")
53
+ else
54
+ self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.ended_at IS NULL OR freeze_tags.ended_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}'")
55
+ end
56
+ end
57
+
58
+ def previously_freeze_tagged(as: nil, list: nil)
59
+ as = as.downcase if self.try(:freeze_tag_case_sensitive)
60
+ if list.present?
61
+ self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.ended_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'")
62
+ else
63
+ self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.ended_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}'")
64
+ end
65
+ end
66
+
67
+ def ever_freeze_tagged(as: nil, list: nil)
68
+ as = as.downcase if self.try(:freeze_tag_case_sensitive)
69
+ if list.present?
70
+ self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'")
71
+ else
72
+ self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.tag = '#{as}'")
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module FreezeTag
2
+ VERSION = "0.1.0"
3
+ end
data/lib/freeze_tag.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "freeze_tag/version"
2
+ require 'freeze_tag/taggable'
3
+ require 'freeze_tag/tag'
4
+
5
+ module FreezeTag
6
+ end
Binary file
Binary file
@@ -0,0 +1,23 @@
1
+ # lib/generators/double_double/install/install_generator.rb
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/migration'
5
+
6
+ module FreezeTag
7
+ module Generators
8
+ class InstallGenerator < ::Rails::Generators::Base
9
+ include Rails::Generators::Migration
10
+ source_root File.expand_path('../templates', __FILE__)
11
+ desc "Add the migrations for DoubleDouble"
12
+
13
+ def self.next_migration_number(path)
14
+ next_migration_number = current_migration_number(path) + 1
15
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
16
+ end
17
+
18
+ def copy_migrations
19
+ migration_template "create_freeze_tag_tables.rb", "db/migrate/create_freeze_tag_tables.rb"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ class CreateFreezeTagTables < ActiveRecord::Migration
2
+ def change
3
+
4
+ raise "Please, make sure you've configured this correctly. Then remove this happy little warning :-)"
5
+
6
+ create_table :freeze_tags do |t|
7
+ t.string :taggable_type, index: true, null: false
8
+ t.string :tag, index: true, null: false
9
+ t.string :list, index: true
10
+ # t.uuid :taggable_id, index: true, null: false # Use this if you're mapping using UUIDs as a primary key
11
+ # t.integer :taggable_id, index: true, null: false # Use this if you're mapping using Integer Primary Keys
12
+ t.datetime :ended_at, index: true
13
+ t.timestamps
14
+ end
15
+
16
+ add_index :freeze_tags, [:taggable_type, :taggable_id, :tag, :ended_at]
17
+ add_index :freeze_tags, [:taggable_type, :taggable_id, :ended_at]
18
+ add_index :freeze_tags, [:tag, :ended_at]
19
+ add_index :freeze_tags, [:taggable_type, :taggable_id, :tag, :list], unique: true, name: "unique"
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freeze_tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Franzen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '9.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '9.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: database_cleaner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.5'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: appraisal
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description:
168
+ email:
169
+ - paul@wework.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".travis.yml"
177
+ - CODE_OF_CONDUCT.md
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - freeze_tag.gemspec
186
+ - lib/freeze_tag.rb
187
+ - lib/freeze_tag/tag.rb
188
+ - lib/freeze_tag/taggable.rb
189
+ - lib/freeze_tag/version.rb
190
+ - lib/generators/.DS_Store
191
+ - lib/generators/freeze_tag/.DS_Store
192
+ - lib/generators/freeze_tag/install/.DS_Store
193
+ - lib/generators/freeze_tag/install/install_generator.rb
194
+ - lib/generators/freeze_tag/install/templates/create_freeze_tag_tables.rb
195
+ homepage: https://wework.com
196
+ licenses:
197
+ - MIT
198
+ metadata: {}
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubyforge_project:
215
+ rubygems_version: 2.6.14
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: A stateless tagging library
219
+ test_files: []