tag_columns 0.1.5 → 0.1.10

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: 24f11ec231a99f562784740d0fac6e7cff7c5d83
4
- data.tar.gz: 07711c4b518ebc23d2204745a10612f4b2ffa7a5
2
+ SHA256:
3
+ metadata.gz: 6ff159c5c446ddf8b7ed9c075a5bdc200d86f752be429de79b0fcfc96460d437
4
+ data.tar.gz: 6c94c7984d4edb22400d3a2c547d20217d1b6985f495aa56884695283b936655
5
5
  SHA512:
6
- metadata.gz: 31d75863702077cfd2d87cd1ebd96feaab89beafbc3057b527196c8f3c1a2f106de80deb9c0a79581ad28df849a0bf3d2054f0a10178c466a877949718264449
7
- data.tar.gz: 4bc98eab66d115fb8caf0f91c9a892d1c539f28e7f0c9a7b22763d2948b3bd01940bd1c4cdfff76a7f43f08cfc1ddd6156ba353cacc44001a76457089f2b04d4
6
+ metadata.gz: d57ab0bf42cc73ece60d40442fa009365246951b05bed00862dcba15a894e867c6cb8df7bcea0711123c05be31a9516e605275940e11743b296c2c92a4176a03
7
+ data.tar.gz: ae6222763a85f42eaea517c81bb065d81b3ccbf77a928948beb9f77c553b0d799c5f150473a18d4cc72f3bcdc981a1bc763bdb281c9622faabbf55fb325e8a8e
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
data/Gemfile.lock CHANGED
@@ -1,82 +1,99 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tag_columns (0.1.5)
4
+ tag_columns (0.1.10)
5
5
  activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.1.4)
10
+ activesupport (6.1.2.1)
11
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)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ ast (2.4.2)
17
+ binding_of_caller (1.0.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.8)
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 (1.0.0)
29
+ docile (1.3.5)
30
+ i18n (1.8.8)
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.5.1)
34
+ method_source (1.0.0)
35
+ minitest (5.14.3)
36
+ os (1.1.1)
37
+ parallel (1.20.1)
38
+ parser (3.0.0.0)
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.6.1)
50
+ binding_of_caller (~> 1.0)
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.3)
60
+ regexp_parser (2.0.3)
61
+ rexml (3.2.4)
62
+ rubocop (1.8.1)
63
+ parallel (~> 1.10)
64
+ parser (>= 3.0.0.0)
65
+ rainbow (>= 2.2.2, < 4.0)
66
+ regexp_parser (>= 1.8, < 3.0)
67
+ rexml
68
+ rubocop-ast (>= 1.2.0, < 2.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, < 3.0)
71
+ rubocop-ast (1.4.1)
72
+ parser (>= 2.7.1.5)
73
+ rubocop-performance (1.9.2)
74
+ rubocop (>= 0.90.0, < 2.0)
75
+ rubocop-ast (>= 0.4.0)
76
+ ruby-progressbar (1.11.0)
77
+ simplecov (0.16.1)
78
+ docile (~> 1.1)
68
79
  json (>= 1.8, < 3)
69
80
  simplecov-html (~> 0.10.0)
70
- simplecov-html (0.10.0)
71
- slop (3.6.0)
72
- term-ansicolor (1.5.0)
81
+ simplecov-html (0.10.2)
82
+ standard (0.12.0)
83
+ rubocop (= 1.8.1)
84
+ rubocop-performance (= 1.9.2)
85
+ standardrb (1.0.0)
86
+ standard
87
+ sync (0.5.0)
88
+ term-ansicolor (1.7.1)
73
89
  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)
90
+ thor (1.1.0)
91
+ tins (1.28.0)
92
+ sync
93
+ tzinfo (2.0.4)
94
+ concurrent-ruby (~> 1.0)
95
+ unicode-display_width (2.0.0)
96
+ zeitwerk (2.4.2)
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.15.4
109
+ 2.1.4
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-89-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
 
@@ -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)
data/bin/loc ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ cloc --exclude-dir=node_modules,test --include-ext=rb,js .
data/bin/standardize ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec standardrb --fix
data/lib/tag_columns.rb CHANGED
@@ -3,10 +3,11 @@ 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
+ return [] if values.nil?
10
11
  values.select(&:present?).map(&:to_s).uniq.sort
11
12
  end
12
13
 
@@ -20,39 +21,80 @@ module TagColumns
20
21
  @tag_columns.each do |column_name, initialized|
21
22
  next if initialized
22
23
 
24
+ column_name = column_name.to_s
23
25
  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
26
+
27
+ define_singleton_method :"unique_#{method_name}" do |conditions = "true"|
28
+ unnest = Arel::Nodes::NamedFunction.new("unnest", [arel_table[column_name]])
29
+ query = distinct.select(unnest)
30
+ .where(conditions)
31
+ .where.not(arel_table[column_name].eq(nil))
32
+ .where.not(arel_table[column_name].eq("{}"))
33
+ connection.execute(query.to_sql).values.flatten.sort
34
+ end
35
+
36
+ define_singleton_method :"#{method_name}_cloud" do |conditions = "true"|
37
+ unnest = Arel::Nodes::NamedFunction.new("unnest", [arel_table[column_name]])
38
+ query = unscoped.select(unnest.as("tag"))
39
+ .where(conditions)
40
+ .where.not(arel_table[column_name].eq(nil))
41
+ .where.not(arel_table[column_name].eq("{}"))
42
+ from(query).group("tag").order("tag").pluck(Arel.sql("tag, count(*) as count"))
36
43
  end
37
44
 
38
- scope :"with_any_#{method_name}", ->(*tags) { where "#{quoted_column_name}::text[] && ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
39
- scope :"with_all_#{method_name}", ->(*tags) { where "#{quoted_column_name}::text[] @> ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
40
- scope :"without_any_#{method_name}", ->(*tags) { where.not "#{quoted_column_name}::text[] && ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
41
- scope :"without_all_#{method_name}", ->(*tags) { where.not "#{quoted_column_name}::text[] @> ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
45
+ scope :"with_#{method_name}", -> {
46
+ where.not(arel_table[column_name].eq(nil)).where.not(arel_table[column_name].eq("{}"))
47
+ }
48
+
49
+ scope :"without_#{method_name}", -> {
50
+ where(arel_table[column_name].eq(nil)).or(where(arel_table[column_name].eq("{}")))
51
+ }
52
+
53
+ scope :"with_any_#{method_name}", ->(*tags) {
54
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
55
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
56
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
57
+ overlap = Arel::Nodes::InfixOperation.new("&&", column_cast, value_cast)
58
+ where overlap
59
+ }
42
60
 
43
- before_validation Proc.new { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
61
+ scope :"with_all_#{method_name}", ->(*tags) {
62
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
63
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
64
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
65
+ contains = Arel::Nodes::InfixOperation.new("@>", column_cast, value_cast)
66
+ where contains
67
+ }
68
+
69
+ scope :"without_any_#{method_name}", ->(*tags) {
70
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
71
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
72
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
73
+ overlap = Arel::Nodes::InfixOperation.new("&&", column_cast, value_cast)
74
+ where.not overlap
75
+ }
76
+
77
+ scope :"without_all_#{method_name}", ->(*tags) {
78
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
79
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
80
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
81
+ contains = Arel::Nodes::InfixOperation.new("@>", column_cast, value_cast)
82
+ where.not contains
83
+ }
84
+
85
+ before_validation -> { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
44
86
 
45
87
  define_method :"has_any_#{method_name}?" do |*values|
46
88
  values = self.class.tag_columns_sanitize_list(values)
47
- existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
89
+ existing = self.class.tag_columns_sanitize_list(self[column_name])
48
90
  (values & existing).present?
49
91
  end
50
92
 
51
93
  define_method :"has_all_#{method_name}?" do |*values|
52
94
  values = self.class.tag_columns_sanitize_list(values)
53
- existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
95
+ existing = self.class.tag_columns_sanitize_list(self[column_name])
54
96
  (values & existing).size == values.size
55
- end
97
+ end
56
98
 
57
99
  alias_method :"has_#{method_name.singularize}?", :"has_all_#{method_name}?"
58
100
 
@@ -1,3 +1,3 @@
1
1
  module TagColumns
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.10"
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
data/tags ADDED
@@ -0,0 +1,12 @@
1
+ !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2
+ !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3
+ !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
4
+ !_TAG_PROGRAM_NAME Exuberant Ctags //
5
+ !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
6
+ !_TAG_PROGRAM_VERSION 5.8 //
7
+ ClassMethods lib/tag_columns.rb /^ module ClassMethods$/;" m class:TagColumns
8
+ TagColumns lib/tag_columns.rb /^module TagColumns$/;" m
9
+ TagColumns lib/tag_columns/version.rb /^module TagColumns$/;" m
10
+ TestTagColumns test/test_tag_columns.rb /^class TestTagColumns < PryTest::Test$/;" c
11
+ tag_columns lib/tag_columns.rb /^ def tag_columns(*column_names)$/;" f class:TagColumns.ClassMethods
12
+ tag_columns_sanitize_list lib/tag_columns.rb /^ def tag_columns_sanitize_list(values = [])$/;" f class:TagColumns.ClassMethods
@@ -4,8 +4,30 @@ Coveralls.wear!
4
4
  SimpleCov.command_name "pry-test"
5
5
  require_relative "../lib/tag_columns"
6
6
 
7
+ class TagColumnsTester
8
+ include TagColumns
9
+ end
10
+
7
11
  class TestTagColumns < PryTest::Test
8
- test "stub" do
9
- assert true
12
+ include TagColumns
13
+
14
+ test "tag_columns_sanitize_list with no arg" do
15
+ assert TagColumnsTester.tag_columns_sanitize_list == []
16
+ end
17
+
18
+ test "tag_columns_sanitize_list with empty list arg" do
19
+ assert TagColumnsTester.tag_columns_sanitize_list([]) == []
20
+ end
21
+
22
+ test "tag_columns_sanitize_list with nil arg" do
23
+ assert TagColumnsTester.tag_columns_sanitize_list(nil) == []
24
+ end
25
+
26
+ test "tag_columns_sanitize_list with upper case list" do
27
+ assert TagColumnsTester.tag_columns_sanitize_list(%w[C B A]) == %w[A B C]
28
+ end
29
+
30
+ test "tag_columns_sanitize_list with lower case list" do
31
+ assert TagColumnsTester.tag_columns_sanitize_list(%w[c b a]) == %w[a b c]
10
32
  end
11
33
  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.5
4
+ version: 0.1.10
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-10-09 00:00:00.000000000 Z
11
+ date: 2021-02-12 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
  - - ">="
@@ -93,9 +93,13 @@ files:
93
93
  - README.md
94
94
  - Rakefile
95
95
  - bin/console
96
+ - bin/loc
96
97
  - bin/setup
98
+ - bin/standardize
97
99
  - lib/tag_columns.rb
98
100
  - lib/tag_columns/version.rb
101
+ - tag_columns.gemspec
102
+ - tags
99
103
  - test/test_tag_columns.rb
100
104
  homepage: https://github.com/hopsoft/tag_columns
101
105
  licenses:
@@ -116,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
120
  - !ruby/object:Gem::Version
117
121
  version: '0'
118
122
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.6.13
123
+ rubygems_version: 3.1.2
121
124
  signing_key:
122
125
  specification_version: 4
123
126
  summary: Fast & simple Rails ActiveRecord model tagging using PostgreSQL's Array datatype