tag_columns 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +92 -0
- data/LICENSE.txt +21 -0
- data/README.md +3 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tag_columns/version.rb +3 -0
- data/lib/tag_columns.rb +51 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 500aa16eedb432395f0e65734d95cdc1e0e18569
|
4
|
+
data.tar.gz: bac6b106f88fd638e8ae32fa94320f43b16823c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93477456535a921860122c33b2ba77693f32ed0bd3acf9a0add40f59ab0c8c86e04ff294afd8fef59cb1217abad16bdc0b766359e6478af39884907781cf1bd0
|
7
|
+
data.tar.gz: f3663c9604bc22ba0ec91a3d71c372677d773abc0cd41dd8b731d346e298de81303721408b84974489ff9ab6692c767420c90ea90fcaf99c16f002a76304ccae
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tag_columns (0.1.0)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (5.0.2)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (~> 0.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
ast (2.3.0)
|
16
|
+
binding_of_caller (0.7.2)
|
17
|
+
debug_inspector (>= 0.0.1)
|
18
|
+
byebug (9.0.6)
|
19
|
+
coderay (1.1.1)
|
20
|
+
concurrent-ruby (1.0.5)
|
21
|
+
coveralls (0.8.20)
|
22
|
+
json (>= 1.8, < 3)
|
23
|
+
simplecov (~> 0.14.1)
|
24
|
+
term-ansicolor (~> 1.3)
|
25
|
+
thor (~> 0.19.4)
|
26
|
+
tins (~> 1.6)
|
27
|
+
debug_inspector (0.0.2)
|
28
|
+
docile (1.1.5)
|
29
|
+
i18n (0.8.1)
|
30
|
+
interception (0.5)
|
31
|
+
json (2.0.4)
|
32
|
+
method_source (0.8.2)
|
33
|
+
minitest (5.10.1)
|
34
|
+
os (1.0.0)
|
35
|
+
parser (2.4.0.0)
|
36
|
+
ast (~> 2.2)
|
37
|
+
powerpack (0.1.1)
|
38
|
+
pry (0.10.4)
|
39
|
+
coderay (~> 1.1.0)
|
40
|
+
method_source (~> 0.8.1)
|
41
|
+
slop (~> 3.4)
|
42
|
+
pry-byebug (3.4.2)
|
43
|
+
byebug (~> 9.0)
|
44
|
+
pry (~> 0.10)
|
45
|
+
pry-rescue (1.4.5)
|
46
|
+
interception (>= 0.5)
|
47
|
+
pry
|
48
|
+
pry-stack_explorer (0.4.9.2)
|
49
|
+
binding_of_caller (>= 0.7)
|
50
|
+
pry (>= 0.9.11)
|
51
|
+
pry-test (0.6.4)
|
52
|
+
os
|
53
|
+
pry
|
54
|
+
pry-byebug
|
55
|
+
pry-rescue
|
56
|
+
pry-stack_explorer
|
57
|
+
rainbow (2.2.1)
|
58
|
+
rake (12.0.0)
|
59
|
+
rubocop (0.48.1)
|
60
|
+
parser (>= 2.3.3.1, < 3.0)
|
61
|
+
powerpack (~> 0.1)
|
62
|
+
rainbow (>= 1.99.1, < 3.0)
|
63
|
+
ruby-progressbar (~> 1.7)
|
64
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
65
|
+
ruby-progressbar (1.8.1)
|
66
|
+
simplecov (0.14.1)
|
67
|
+
docile (~> 1.1.0)
|
68
|
+
json (>= 1.8, < 3)
|
69
|
+
simplecov-html (~> 0.10.0)
|
70
|
+
simplecov-html (0.10.0)
|
71
|
+
slop (3.6.0)
|
72
|
+
term-ansicolor (1.5.0)
|
73
|
+
tins (~> 1.0)
|
74
|
+
thor (0.19.4)
|
75
|
+
thread_safe (0.3.6)
|
76
|
+
tins (1.13.2)
|
77
|
+
tzinfo (1.2.3)
|
78
|
+
thread_safe (~> 0.1)
|
79
|
+
unicode-display_width (1.2.1)
|
80
|
+
|
81
|
+
PLATFORMS
|
82
|
+
ruby
|
83
|
+
|
84
|
+
DEPENDENCIES
|
85
|
+
coveralls
|
86
|
+
pry-test
|
87
|
+
rake
|
88
|
+
rubocop
|
89
|
+
tag_columns!
|
90
|
+
|
91
|
+
BUNDLED WITH
|
92
|
+
1.14.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Nathan Hopkins
|
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
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tag_columns"
|
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
data/lib/tag_columns.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
require "active_support/core_ext/string/inflections"
|
3
|
+
require "tag_columns/version"
|
4
|
+
|
5
|
+
module TagColumns
|
6
|
+
extend ::ActiveSupport::Concern
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def tag_columns_sanitize_list(values=[])
|
10
|
+
values.select(&:present?).map(&:to_s).uniq.sort
|
11
|
+
end
|
12
|
+
|
13
|
+
def tag_columns(*column_names)
|
14
|
+
@tag_columns ||= {}
|
15
|
+
|
16
|
+
tag_columns_sanitize_list(column_names).each do |column_name|
|
17
|
+
@tag_columns[column_name] ||= false
|
18
|
+
end
|
19
|
+
|
20
|
+
@tag_columns.each do |column_name, initialized|
|
21
|
+
next if initialized
|
22
|
+
|
23
|
+
column_name_plural = column_name.pluralize
|
24
|
+
quoted_column_name = "#{quoted_table_name}.#{connection.quote_column_name column_name}"
|
25
|
+
|
26
|
+
scope :"with_any_#{column_name}", ->(*tags) { where "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
27
|
+
scope :"with_all_#{column_name}", ->(*tags) { where "#{quoted_column_name} @> ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
28
|
+
scope :"without_any_#{column_name}", ->(*tags) { where.not "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
29
|
+
scope :"without_all_#{column_name}", ->(*tags) { where.not "#{quoted_column_name} @> ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
30
|
+
|
31
|
+
before_validation Proc.new { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
|
32
|
+
|
33
|
+
define_method :"has_any_#{column_name_plural}?" do |*values|
|
34
|
+
values = self.class.tag_columns_sanitize_list(values)
|
35
|
+
existing = self[column_name] || []
|
36
|
+
(values & existing).present?
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :"has_#{column_name_plural}?", :"has_any_#{column_name_plural}?"
|
40
|
+
|
41
|
+
define_method :"has_all_#{column_name_plural}?" do |*values|
|
42
|
+
values = self.class.tag_columns_sanitize_list(values)
|
43
|
+
existing = self[column_name] || []
|
44
|
+
(values & existing).size == values.size
|
45
|
+
end
|
46
|
+
|
47
|
+
@tag_columns[column_name] = true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tag_columns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Hopkins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- natehop@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/tag_columns.rb
|
98
|
+
- lib/tag_columns/version.rb
|
99
|
+
homepage: https://github.com/hopsoft/tag_columns
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.6.11
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Work in progress
|
123
|
+
test_files: []
|