tag_columns 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +21 -2
- data/lib/tag_columns.rb +13 -1
- data/lib/tag_columns/version.rb +1 -1
- data/test/test_tag_columns.rb +11 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: defa7c70b8eab8d413f513c5b9941b1e5511ae49
|
4
|
+
data.tar.gz: e4beea230867f5bacb9c7ead7ab372bc323ee18c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc061350f163cb0b9ba87ac398c48dbbf676acf6e7d8dd737e71848d3ed7e6072aa107d4c1c4990c90d150f9af6999f5b50c2481d1caaf1ec5fa9e402c8b7bfe
|
7
|
+
data.tar.gz: 61f90575de2bf67f1d252bf4b6f94d109c504434a03c1f8ec5a345e8eb53f6fc9f2780204105970a6a028e7cf9d008f3e79c07e7d466cef178f500fb241bfbec
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tag_columns (0.1.
|
4
|
+
tag_columns (0.1.4)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (5.
|
10
|
+
activesupport (5.1.2)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (~> 0.7)
|
13
13
|
minitest (~> 5.1)
|
@@ -26,11 +26,11 @@ GEM
|
|
26
26
|
tins (~> 1.6)
|
27
27
|
debug_inspector (0.0.2)
|
28
28
|
docile (1.1.5)
|
29
|
-
i18n (0.8.
|
29
|
+
i18n (0.8.6)
|
30
30
|
interception (0.5)
|
31
31
|
json (2.0.4)
|
32
32
|
method_source (0.8.2)
|
33
|
-
minitest (5.10.
|
33
|
+
minitest (5.10.3)
|
34
34
|
os (1.0.0)
|
35
35
|
parser (2.4.0.0)
|
36
36
|
ast (~> 2.2)
|
data/README.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
[![Lines of Code](http://img.shields.io/badge/lines_of_code-53-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
|
2
|
+
[![Code Status](http://img.shields.io/codeclimate/github/hopsoft/tag_columns.svg?style=flat)](https://codeclimate.com/github/hopsoft/tag_columns)
|
3
|
+
[![Dependency Status](http://img.shields.io/gemnasium/hopsoft/tag_columns.svg?style=flat)](https://gemnasium.com/hopsoft/tag_columns)
|
4
|
+
[![Build Status](http://img.shields.io/travis/hopsoft/tag_columns.svg?style=flat)](https://travis-ci.org/hopsoft/tag_columns)
|
5
|
+
[![Coverage Status](https://img.shields.io/coveralls/hopsoft/tag_columns.svg?style=flat)](https://coveralls.io/r/hopsoft/tag_columns?branch=master)
|
6
|
+
[![Downloads](http://img.shields.io/gem/dt/tag_columns.svg?style=flat)](http://rubygems.org/gems/tag_columns)
|
7
|
+
|
8
|
+
[![Sponsor](https://app.codesponsor.io/embed/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/tag_columns.svg)](https://app.codesponsor.io/link/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/tag_columns)
|
9
|
+
|
1
10
|
# TagColumns
|
2
11
|
|
3
|
-
Fast & simple model tagging using [PostgreSQL's](https://www.postgresql.org/) [Array datatype](https://www.postgresql.org/docs/current/static/arrays.html).
|
12
|
+
Fast & simple Rails ActiveRecord model tagging using [PostgreSQL's](https://www.postgresql.org/) [Array datatype](https://www.postgresql.org/docs/current/static/arrays.html).
|
13
|
+
|
4
14
|
*Similar to [acts_as_taggable_on](https://github.com/mbleigh/acts-as-taggable-on) but lighter weight with fewer features.*
|
15
|
+
*Also, be sure to check out [acts_as_taggable_array_on](https://github.com/tmiyamon/acts-as-taggable-array-on).*
|
5
16
|
|
6
17
|
## Use Cases
|
7
18
|
|
@@ -29,8 +40,10 @@ end
|
|
29
40
|
```
|
30
41
|
|
31
42
|
```ruby
|
43
|
+
# app/models/user.rb
|
32
44
|
class User < ApplicationRecord
|
33
|
-
include
|
45
|
+
include TagColumns
|
46
|
+
tag_columns :groups
|
34
47
|
end
|
35
48
|
```
|
36
49
|
|
@@ -53,4 +66,10 @@ non_writers = User.without_any_groups(:writer)
|
|
53
66
|
readers_or_writers = User.with_any_groups(:reader, :writer)
|
54
67
|
readers_and_writers = User.with_all_groups(:reader, :writer)
|
55
68
|
non_readers_and_writers = User.without_all_groups(:reader, :writer)
|
69
|
+
|
70
|
+
# find unique tags across all users
|
71
|
+
User.unique_groups
|
72
|
+
|
73
|
+
# find unique tags for users with the last name 'Smith'
|
74
|
+
User.unique_groups(last_name: "Smith")
|
56
75
|
```
|
data/lib/tag_columns.rb
CHANGED
@@ -23,6 +23,18 @@ module TagColumns
|
|
23
23
|
method_name = column_name.downcase
|
24
24
|
quoted_column_name = "#{quoted_table_name}.#{connection.quote_column_name column_name}"
|
25
25
|
|
26
|
+
define_singleton_method :"unique_#{method_name}" do |conditions='true'|
|
27
|
+
result = connection.execute <<~QUERY
|
28
|
+
SELECT DISTINCT unnest(#{quoted_column_name}) AS unique_#{method_name}
|
29
|
+
FROM #{quoted_table_name}
|
30
|
+
WHERE #{where(conditions).to_sql.split(/ WHERE /i).last}
|
31
|
+
AND #{quoted_column_name} IS NOT NULL
|
32
|
+
AND #{quoted_column_name} != '{}'
|
33
|
+
ORDER BY unique_#{method_name}
|
34
|
+
QUERY
|
35
|
+
result.values.flatten
|
36
|
+
end
|
37
|
+
|
26
38
|
scope :"with_any_#{method_name}", ->(*tags) { where "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
27
39
|
scope :"with_all_#{method_name}", ->(*tags) { where "#{quoted_column_name} @> ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
28
40
|
scope :"without_any_#{method_name}", ->(*tags) { where.not "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
@@ -40,7 +52,7 @@ module TagColumns
|
|
40
52
|
values = self.class.tag_columns_sanitize_list(values)
|
41
53
|
existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
|
42
54
|
(values & existing).size == values.size
|
43
|
-
|
55
|
+
end
|
44
56
|
|
45
57
|
alias_method :"has_#{method_name.singularize}?", :"has_all_#{method_name}?"
|
46
58
|
|
data/lib/tag_columns/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tag_columns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- bin/setup
|
97
97
|
- lib/tag_columns.rb
|
98
98
|
- lib/tag_columns/version.rb
|
99
|
+
- test/test_tag_columns.rb
|
99
100
|
homepage: https://github.com/hopsoft/tag_columns
|
100
101
|
licenses:
|
101
102
|
- MIT
|
@@ -119,5 +120,6 @@ rubyforge_project:
|
|
119
120
|
rubygems_version: 2.6.11
|
120
121
|
signing_key:
|
121
122
|
specification_version: 4
|
122
|
-
summary: Fast & simple model tagging using PostgreSQL's Array datatype
|
123
|
-
test_files:
|
123
|
+
summary: Fast & simple Rails ActiveRecord model tagging using PostgreSQL's Array datatype
|
124
|
+
test_files:
|
125
|
+
- test/test_tag_columns.rb
|