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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70fdfc0271ea3299c00a03617d8ac8ab3c1aa922
4
- data.tar.gz: 59f0c97926eb432b77ee06449d0c8ae185bc7af9
3
+ metadata.gz: 916161bd2f1a95730ddd6801964cf49db63031dc
4
+ data.tar.gz: 841bfffd779bf8bcbeeac455f88cd9e7793f3942
5
5
  SHA512:
6
- metadata.gz: a6c2a2898846a98c5aa13356866d1cddd709d0a2025799bd3166bcedbdd0c2b92b46756bf4855e22a9a5c040c486fc34d4f25b6c4a212b9e0caef9caca102159
7
- data.tar.gz: 2474138516e22364189e4a84339ff80226391ca44be868904a00e6ddb3c03cf28676a7ebfb575761ea76238a79b183c974ae9e76dfec03a4823f6a91de7e7f8c
6
+ metadata.gz: 4ee1165ec2966aa7899a25a630a6608328b743879ea6fe6bc92ef977b60637feaf44b28252e433621130d023ddb5d815ffa20f9e34c6bda6838fe46152bd2554
7
+ data.tar.gz: 3efc49aefd5ceeab7989b9aa568e9ce9d6ea16230eedb915109c49fcb1bed47c34f7b73ebe991fcc95d1063ee9b2a9011efbb7b10d605d88dbda0164b7f0e7d2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tag_columns (0.1.1)
4
+ tag_columns (0.1.2)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,3 +1,56 @@
1
1
  # TagColumns
2
2
 
3
- This is a work in progress.
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
@@ -1,2 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+
3
+ task default: [:test]
4
+
5
+ task :test do
6
+ exec "bundle exec pry-test --disable-pry"
7
+ end
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
@@ -1,3 +1,3 @@
1
1
  module TagColumns
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-13 00:00:00.000000000 Z
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: Work in progress
122
+ summary: Fast & simple model tagging using PostgreSQL's Array datatype
123
123
  test_files: []