tag_columns 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +54 -1
- data/Rakefile +6 -1
- data/lib/tag_columns.rb +2 -2
- data/lib/tag_columns/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 916161bd2f1a95730ddd6801964cf49db63031dc
|
4
|
+
data.tar.gz: 841bfffd779bf8bcbeeac455f88cd9e7793f3942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ee1165ec2966aa7899a25a630a6608328b743879ea6fe6bc92ef977b60637feaf44b28252e433621130d023ddb5d815ffa20f9e34c6bda6838fe46152bd2554
|
7
|
+
data.tar.gz: 3efc49aefd5ceeab7989b9aa568e9ce9d6ea16230eedb915109c49fcb1bed47c34f7b73ebe991fcc95d1063ee9b2a9011efbb7b10d605d88dbda0164b7f0e7d2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,56 @@
|
|
1
1
|
# TagColumns
|
2
2
|
|
3
|
-
|
3
|
+
Fast & simple model tagging using [PostgreSQL's](https://www.postgresql.org/) [Array datatype](https://www.postgresql.org/docs/current/static/arrays.html).
|
4
|
+
*Similar to [acts_as_taggable_on](https://github.com/mbleigh/acts-as-taggable-on) but lighter weight with fewer features.*
|
5
|
+
|
6
|
+
## Use Cases
|
7
|
+
|
8
|
+
Assign categories to your database records.
|
9
|
+
|
10
|
+
* Assign multiple groups to user records
|
11
|
+
* Assign categories to blog posts et al.
|
12
|
+
* etc...
|
13
|
+
|
14
|
+
## Quick Start
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# Gemfile
|
18
|
+
gem "tag_columns"
|
19
|
+
```
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# db/migrate/TIMESTAMP_add_groups_to_user.rb
|
23
|
+
class AddGroupsToUser < ActiveRecord::Migration[5.0]
|
24
|
+
def change
|
25
|
+
add_column :users, :groups, :string, array: true, default: "{}", null: false
|
26
|
+
add_index :users, :groups, using: "gin"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class User < ApplicationRecord
|
33
|
+
include SelfRenderer
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
user = User.find(1)
|
39
|
+
|
40
|
+
# assigning tags
|
41
|
+
user.groups << :reader
|
42
|
+
user.groups << :writer
|
43
|
+
user.save
|
44
|
+
|
45
|
+
# checking tags
|
46
|
+
is_writer = user.has_group?(:writer)
|
47
|
+
is_reader_or_writer = user.has_any_groups?(:reader, :writer)
|
48
|
+
is_reader_and_writer = user.has_all_groups?(:reader, :writer)
|
49
|
+
|
50
|
+
# finding tagged records
|
51
|
+
writers = User.with_any_groups(:writer)
|
52
|
+
non_writers = User.without_any_groups(:writer)
|
53
|
+
readers_or_writers = User.with_any_groups(:reader, :writer)
|
54
|
+
readers_and_writers = User.with_all_groups(:reader, :writer)
|
55
|
+
non_readers_and_writers = User.without_all_groups(:reader, :writer)
|
56
|
+
```
|
data/Rakefile
CHANGED
data/lib/tag_columns.rb
CHANGED
@@ -36,14 +36,14 @@ module TagColumns
|
|
36
36
|
(values & existing).present?
|
37
37
|
end
|
38
38
|
|
39
|
-
alias_method :"has_#{method_name.singularize}?", :"has_any_#{method_name}?"
|
40
|
-
|
41
39
|
define_method :"has_all_#{method_name}?" do |*values|
|
42
40
|
values = self.class.tag_columns_sanitize_list(values)
|
43
41
|
existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
|
44
42
|
(values & existing).size == values.size
|
45
43
|
end
|
46
44
|
|
45
|
+
alias_method :"has_#{method_name.singularize}?", :"has_all_#{method_name}?"
|
46
|
+
|
47
47
|
@tag_columns[column_name] = true
|
48
48
|
end
|
49
49
|
end
|
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.2
|
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-04-
|
11
|
+
date: 2017-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -119,5 +119,5 @@ rubyforge_project:
|
|
119
119
|
rubygems_version: 2.6.11
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
|
-
summary:
|
122
|
+
summary: Fast & simple model tagging using PostgreSQL's Array datatype
|
123
123
|
test_files: []
|