tag_columns 0.1.4 → 0.1.9

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
- SHA1:
3
- metadata.gz: defa7c70b8eab8d413f513c5b9941b1e5511ae49
4
- data.tar.gz: e4beea230867f5bacb9c7ead7ab372bc323ee18c
2
+ SHA256:
3
+ metadata.gz: 1bb5849e125d7d342653151b9376d43d904867a31c05df4716efde6f7a91d608
4
+ data.tar.gz: 55a5b086ac67b2cde68c7befd6707d084d49e388357a940d21e1500d764c8a2e
5
5
  SHA512:
6
- metadata.gz: cc061350f163cb0b9ba87ac398c48dbbf676acf6e7d8dd737e71848d3ed7e6072aa107d4c1c4990c90d150f9af6999f5b50c2481d1caaf1ec5fa9e402c8b7bfe
7
- data.tar.gz: 61f90575de2bf67f1d252bf4b6f94d109c504434a03c1f8ec5a345e8eb53f6fc9f2780204105970a6a028e7cf9d008f3e79c07e7d466cef178f500fb241bfbec
6
+ metadata.gz: f6fc69ae96f44815701774dee9b58fb72d51080c0c5930ddefa1cd2ee14a9ac444374cf1939b5a7133fdd56341a6be6c9410892476b6f6e83ee29c90c6115436
7
+ data.tar.gz: 46f4f957e0f95c4d4177345f7bcffa3ce46416f3d9a6d93eb47e4e6c619dabe423a32ab31e0e5fcaddeb1a7f71314f37d107f99e63643c550ab1f2259a8c7c2f
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in tag_columns.gemspec
4
4
  gemspec
@@ -1,82 +1,99 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tag_columns (0.1.4)
4
+ tag_columns (0.1.9)
5
5
  activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.1.2)
10
+ activesupport (6.0.3.2)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (~> 0.7)
12
+ i18n (>= 0.7, < 2)
13
13
  minitest (~> 5.1)
14
14
  tzinfo (~> 1.1)
15
- ast (2.3.0)
16
- binding_of_caller (0.7.2)
15
+ zeitwerk (~> 2.2, >= 2.2.2)
16
+ ast (2.4.1)
17
+ binding_of_caller (0.8.0)
17
18
  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)
19
+ byebug (11.1.3)
20
+ coderay (1.1.3)
21
+ concurrent-ruby (1.1.7)
22
+ coveralls (0.8.23)
22
23
  json (>= 1.8, < 3)
23
- simplecov (~> 0.14.1)
24
+ simplecov (~> 0.16.1)
24
25
  term-ansicolor (~> 1.3)
25
- thor (~> 0.19.4)
26
+ thor (>= 0.19.4, < 2.0)
26
27
  tins (~> 1.6)
27
- debug_inspector (0.0.2)
28
- docile (1.1.5)
29
- i18n (0.8.6)
28
+ debug_inspector (0.0.3)
29
+ docile (1.3.2)
30
+ i18n (1.8.5)
31
+ concurrent-ruby (~> 1.0)
30
32
  interception (0.5)
31
- json (2.0.4)
32
- method_source (0.8.2)
33
- minitest (5.10.3)
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)
33
+ json (2.3.1)
34
+ method_source (1.0.0)
35
+ minitest (5.14.1)
36
+ os (1.1.1)
37
+ parallel (1.19.2)
38
+ parser (2.7.1.4)
39
+ ast (~> 2.4.1)
40
+ pry (0.13.1)
41
+ coderay (~> 1.1)
42
+ method_source (~> 1.0)
43
+ pry-byebug (3.9.0)
44
+ byebug (~> 11.0)
45
+ pry (~> 0.13.0)
46
+ pry-rescue (1.5.2)
46
47
  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)
48
+ pry (>= 0.12.0)
49
+ pry-stack_explorer (0.5.1)
50
+ binding_of_caller (~> 0.7)
51
+ pry (~> 0.13)
52
+ pry-test (0.6.6)
52
53
  os
53
54
  pry
54
55
  pry-byebug
55
56
  pry-rescue
56
57
  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)
58
+ rainbow (3.0.0)
59
+ rake (13.0.1)
60
+ regexp_parser (1.7.1)
61
+ rexml (3.2.4)
62
+ rubocop (0.89.1)
63
+ parallel (~> 1.10)
64
+ parser (>= 2.7.1.1)
65
+ rainbow (>= 2.2.2, < 4.0)
66
+ regexp_parser (>= 1.7)
67
+ rexml
68
+ rubocop-ast (>= 0.3.0, < 1.0)
63
69
  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)
70
+ unicode-display_width (>= 1.4.0, < 2.0)
71
+ rubocop-ast (0.3.0)
72
+ parser (>= 2.7.1.4)
73
+ rubocop-performance (1.7.1)
74
+ rubocop (>= 0.82.0)
75
+ ruby-progressbar (1.10.1)
76
+ simplecov (0.16.1)
77
+ docile (~> 1.1)
68
78
  json (>= 1.8, < 3)
69
79
  simplecov-html (~> 0.10.0)
70
- simplecov-html (0.10.0)
71
- slop (3.6.0)
72
- term-ansicolor (1.5.0)
80
+ simplecov-html (0.10.2)
81
+ standard (0.5.2)
82
+ rubocop (~> 0.89.1)
83
+ rubocop-performance (~> 1.7.1)
84
+ standardrb (1.0.0)
85
+ standard
86
+ sync (0.5.0)
87
+ term-ansicolor (1.7.1)
73
88
  tins (~> 1.0)
74
- thor (0.19.4)
89
+ thor (1.0.1)
75
90
  thread_safe (0.3.6)
76
- tins (1.13.2)
77
- tzinfo (1.2.3)
91
+ tins (1.25.0)
92
+ sync
93
+ tzinfo (1.2.7)
78
94
  thread_safe (~> 0.1)
79
- unicode-display_width (1.2.1)
95
+ unicode-display_width (1.7.0)
96
+ zeitwerk (2.4.0)
80
97
 
81
98
  PLATFORMS
82
99
  ruby
@@ -85,8 +102,8 @@ DEPENDENCIES
85
102
  coveralls
86
103
  pry-test
87
104
  rake
88
- rubocop
105
+ standardrb
89
106
  tag_columns!
90
107
 
91
108
  BUNDLED WITH
92
- 1.14.6
109
+ 1.17.2
data/README.md CHANGED
@@ -1,16 +1,12 @@
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)
1
+ [![Lines of Code](http://img.shields.io/badge/lines_of_code-88-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/7503486b1bb494b5d976/maintainability)](https://codeclimate.com/github/hopsoft/tag_columns/maintainability)
4
3
  [![Build Status](http://img.shields.io/travis/hopsoft/tag_columns.svg?style=flat)](https://travis-ci.org/hopsoft/tag_columns)
5
4
  [![Coverage Status](https://img.shields.io/coveralls/hopsoft/tag_columns.svg?style=flat)](https://coveralls.io/r/hopsoft/tag_columns?branch=master)
6
5
  [![Downloads](http://img.shields.io/gem/dt/tag_columns.svg?style=flat)](http://rubygems.org/gems/tag_columns)
7
6
 
8
- [![Sponsor](https://app.codesponsor.io/embed/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/tag_columns.svg)](https://app.codesponsor.io/link/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/tag_columns)
9
-
10
7
  # TagColumns
11
8
 
12
9
  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
-
14
10
  *Similar to [acts_as_taggable_on](https://github.com/mbleigh/acts-as-taggable-on) but lighter weight with fewer features.*
15
11
  *Also, be sure to check out [acts_as_taggable_array_on](https://github.com/tmiyamon/acts-as-taggable-array-on).*
16
12
 
@@ -33,7 +29,7 @@ gem "tag_columns"
33
29
  # db/migrate/TIMESTAMP_add_groups_to_user.rb
34
30
  class AddGroupsToUser < ActiveRecord::Migration[5.0]
35
31
  def change
36
- add_column :users, :groups, :string, array: true, default: "{}", null: false
32
+ add_column :users, :groups, :string, array: true, default: [], null: false
37
33
  add_index :users, :groups, using: "gin"
38
34
  end
39
35
  end
@@ -61,6 +57,8 @@ is_reader_or_writer = user.has_any_groups?(:reader, :writer)
61
57
  is_reader_and_writer = user.has_all_groups?(:reader, :writer)
62
58
 
63
59
  # finding tagged records
60
+ assigned = User.with_groups
61
+ unassigned = User.without_groups
64
62
  writers = User.with_any_groups(:writer)
65
63
  non_writers = User.without_any_groups(:writer)
66
64
  readers_or_writers = User.with_any_groups(:reader, :writer)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec standardrb --fix
@@ -3,10 +3,10 @@ require "active_support/core_ext/string/inflections"
3
3
  require "tag_columns/version"
4
4
 
5
5
  module TagColumns
6
- extend ::ActiveSupport::Concern
6
+ extend ActiveSupport::Concern
7
7
 
8
8
  module ClassMethods
9
- def tag_columns_sanitize_list(values=[])
9
+ def tag_columns_sanitize_list(values = [])
10
10
  values.select(&:present?).map(&:to_s).uniq.sort
11
11
  end
12
12
 
@@ -20,27 +20,68 @@ module TagColumns
20
20
  @tag_columns.each do |column_name, initialized|
21
21
  next if initialized
22
22
 
23
+ column_name = column_name.to_s
23
24
  method_name = column_name.downcase
24
- quoted_column_name = "#{quoted_table_name}.#{connection.quote_column_name column_name}"
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
25
+
26
+ define_singleton_method :"unique_#{method_name}" do |conditions = "true"|
27
+ unnest = Arel::Nodes::NamedFunction.new("unnest", [arel_table[column_name]])
28
+ query = distinct.select(unnest)
29
+ .where(conditions)
30
+ .where.not(arel_table[column_name].eq(nil))
31
+ .where.not(arel_table[column_name].eq("{}"))
32
+ connection.execute(query.to_sql).values.flatten.sort
33
+ end
34
+
35
+ define_singleton_method :"#{method_name}_cloud" do |conditions = "true"|
36
+ unnest = Arel::Nodes::NamedFunction.new("unnest", [arel_table[column_name]])
37
+ query = unscoped.select(unnest.as("tag"))
38
+ .where(conditions)
39
+ .where.not(arel_table[column_name].eq(nil))
40
+ .where.not(arel_table[column_name].eq("{}"))
41
+ from(query).group("tag").order("tag").pluck(Arel.sql("tag, count(*) as count"))
36
42
  end
37
43
 
38
- scope :"with_any_#{method_name}", ->(*tags) { where "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
39
- scope :"with_all_#{method_name}", ->(*tags) { where "#{quoted_column_name} @> ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
40
- scope :"without_any_#{method_name}", ->(*tags) { where.not "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
41
- scope :"without_all_#{method_name}", ->(*tags) { where.not "#{quoted_column_name} @> ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
44
+ scope :"with_#{method_name}", -> {
45
+ where.not(arel_table[column_name].eq(nil)).where.not(arel_table[column_name].eq("{}"))
46
+ }
47
+
48
+ scope :"without_#{method_name}", -> {
49
+ where(arel_table[column_name].eq(nil)).or(where(arel_table[column_name].eq("{}")))
50
+ }
51
+
52
+ scope :"with_any_#{method_name}", ->(*tags) {
53
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
54
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
55
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
56
+ overlap = Arel::Nodes::InfixOperation.new("&&", column_cast, value_cast)
57
+ where overlap
58
+ }
42
59
 
43
- before_validation Proc.new { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
60
+ scope :"with_all_#{method_name}", ->(*tags) {
61
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
62
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
63
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
64
+ contains = Arel::Nodes::InfixOperation.new("@>", column_cast, value_cast)
65
+ where contains
66
+ }
67
+
68
+ scope :"without_any_#{method_name}", ->(*tags) {
69
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
70
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
71
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
72
+ overlap = Arel::Nodes::InfixOperation.new("&&", column_cast, value_cast)
73
+ where.not overlap
74
+ }
75
+
76
+ scope :"without_all_#{method_name}", ->(*tags) {
77
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
78
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
79
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
80
+ contains = Arel::Nodes::InfixOperation.new("@>", column_cast, value_cast)
81
+ where.not contains
82
+ }
83
+
84
+ before_validation -> { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
44
85
 
45
86
  define_method :"has_any_#{method_name}?" do |*values|
46
87
  values = self.class.tag_columns_sanitize_list(values)
@@ -52,7 +93,7 @@ module TagColumns
52
93
  values = self.class.tag_columns_sanitize_list(values)
53
94
  existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
54
95
  (values & existing).size == values.size
55
- end
96
+ end
56
97
 
57
98
  alias_method :"has_#{method_name.singularize}?", :"has_all_#{method_name}?"
58
99
 
@@ -1,3 +1,3 @@
1
1
  module TagColumns
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -0,0 +1,21 @@
1
+ require File.expand_path("../lib/tag_columns/version", __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "tag_columns"
5
+ gem.license = "MIT"
6
+ gem.version = TagColumns::VERSION
7
+ gem.authors = ["Nathan Hopkins"]
8
+ gem.email = ["natehop@gmail.com"]
9
+ gem.homepage = "https://github.com/hopsoft/tag_columns"
10
+ gem.summary = "Fast & simple Rails ActiveRecord model tagging using PostgreSQL's Array datatype"
11
+
12
+ gem.files = Dir["lib/**/*.rb", "bin/*", "[A-Z]*"]
13
+ gem.test_files = Dir["test/**/*.rb"]
14
+
15
+ gem.add_dependency "activesupport"
16
+
17
+ gem.add_development_dependency "rake"
18
+ gem.add_development_dependency "pry-test"
19
+ gem.add_development_dependency "coveralls"
20
+ gem.add_development_dependency "standardrb"
21
+ 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.4
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-01 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: standardrb
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
85
  - natehop@gmail.com
86
86
  executables: []
@@ -94,14 +94,16 @@ files:
94
94
  - Rakefile
95
95
  - bin/console
96
96
  - bin/setup
97
+ - bin/standardize
97
98
  - lib/tag_columns.rb
98
99
  - lib/tag_columns/version.rb
100
+ - tag_columns.gemspec
99
101
  - test/test_tag_columns.rb
100
102
  homepage: https://github.com/hopsoft/tag_columns
101
103
  licenses:
102
104
  - MIT
103
105
  metadata: {}
104
- post_install_message:
106
+ post_install_message:
105
107
  rdoc_options: []
106
108
  require_paths:
107
109
  - lib
@@ -116,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  - !ruby/object:Gem::Version
117
119
  version: '0'
118
120
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.6.11
121
- signing_key:
121
+ rubygems_version: 3.0.3
122
+ signing_key:
122
123
  specification_version: 4
123
124
  summary: Fast & simple Rails ActiveRecord model tagging using PostgreSQL's Array datatype
124
125
  test_files: