tag_columns 0.1.6 → 0.1.7

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: 7ff5c636e80445d9004a6a73f81bb00c2759bd52
4
- data.tar.gz: cc7a8f4f24b8c444cca1d505bd2c20d0c536271c
2
+ SHA256:
3
+ metadata.gz: 76c6ce1985882f48d00cd3120f5364f66d253a491f885c4a35803c1289e79af3
4
+ data.tar.gz: 01454b2b479b28064e9904f80c89da5ddbd5c99515de50a8f5fa1d1faf3f1f0d
5
5
  SHA512:
6
- metadata.gz: b94d8debbfc4bebd2dfd6ccfb2e42e0b28f8c31473bc089b37c488fef2e91f065bc26e9334390ffd101465255e4103b848c3c11271694482b765cb6aa9c051ef
7
- data.tar.gz: 5da5092f088610e1cc9bcb7d166ddf187a049037ce66f2d0b7ef80d64096cbef95e14f1024c881f619dacd5230b734aca9142dcdce40bf0d1ed0fc234f206292
6
+ metadata.gz: cc896caf28cc640b4a90511808ceb7f55c2b78383ec5121b392970990a31d4232aa49097a9f6daf887f231b87b033a7ffc92d8919c00a0e97bc7f51bb9cb544e
7
+ data.tar.gz: baa4821466bada3737e7bad0853ae9e1664621aff742475915bab595d63cec50db26264de6dcc2db291352dbf144150ac6b9f99f1e032597bf786dbf3fdeb0aa
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,68 +1,66 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tag_columns (0.1.6)
4
+ tag_columns (0.1.7)
5
5
  activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.1.5)
10
+ activesupport (5.2.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
- binding_of_caller (0.7.2)
15
+ binding_of_caller (0.8.0)
16
16
  debug_inspector (>= 0.0.1)
17
- byebug (9.0.6)
18
- coderay (1.1.1)
19
- concurrent-ruby (1.0.5)
20
- coveralls (0.8.20)
17
+ byebug (10.0.2)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.1.4)
20
+ coveralls (0.8.22)
21
21
  json (>= 1.8, < 3)
22
- simplecov (~> 0.14.1)
22
+ simplecov (~> 0.16.1)
23
23
  term-ansicolor (~> 1.3)
24
24
  thor (~> 0.19.4)
25
25
  tins (~> 1.6)
26
- debug_inspector (0.0.2)
27
- docile (1.1.5)
28
- i18n (0.9.5)
26
+ debug_inspector (0.0.3)
27
+ docile (1.3.1)
28
+ i18n (1.5.3)
29
29
  concurrent-ruby (~> 1.0)
30
30
  interception (0.5)
31
- json (2.0.4)
32
- method_source (0.8.2)
31
+ json (2.1.0)
32
+ method_source (0.9.2)
33
33
  minitest (5.11.3)
34
34
  os (1.0.0)
35
- pry (0.10.4)
35
+ pry (0.12.2)
36
36
  coderay (~> 1.1.0)
37
- method_source (~> 0.8.1)
38
- slop (~> 3.4)
39
- pry-byebug (3.4.2)
40
- byebug (~> 9.0)
37
+ method_source (~> 0.9.0)
38
+ pry-byebug (3.6.0)
39
+ byebug (~> 10.0)
41
40
  pry (~> 0.10)
42
- pry-rescue (1.4.5)
41
+ pry-rescue (1.5.0)
43
42
  interception (>= 0.5)
44
- pry
45
- pry-stack_explorer (0.4.9.2)
43
+ pry (>= 0.12.0)
44
+ pry-stack_explorer (0.4.9.3)
46
45
  binding_of_caller (>= 0.7)
47
46
  pry (>= 0.9.11)
48
- pry-test (0.6.4)
47
+ pry-test (0.6.5)
49
48
  os
50
49
  pry
51
50
  pry-byebug
52
51
  pry-rescue
53
52
  pry-stack_explorer
54
- rake (12.0.0)
55
- simplecov (0.14.1)
56
- docile (~> 1.1.0)
53
+ rake (12.3.2)
54
+ simplecov (0.16.1)
55
+ docile (~> 1.1)
57
56
  json (>= 1.8, < 3)
58
57
  simplecov-html (~> 0.10.0)
59
- simplecov-html (0.10.0)
60
- slop (3.6.0)
61
- term-ansicolor (1.5.0)
58
+ simplecov-html (0.10.2)
59
+ term-ansicolor (1.7.1)
62
60
  tins (~> 1.0)
63
61
  thor (0.19.4)
64
62
  thread_safe (0.3.6)
65
- tins (1.13.2)
63
+ tins (1.20.2)
66
64
  tzinfo (1.2.5)
67
65
  thread_safe (~> 0.1)
68
66
 
@@ -76,4 +74,4 @@ DEPENDENCIES
76
74
  tag_columns!
77
75
 
78
76
  BUNDLED WITH
79
- 1.16.0
77
+ 1.17.2
data/README.md CHANGED
@@ -1,6 +1,5 @@
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/)
1
+ [![Lines of Code](http://img.shields.io/badge/lines_of_code-68-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/7503486b1bb494b5d976/maintainability)](https://codeclimate.com/github/hopsoft/tag_columns/maintainability)
3
- [![Dependency Status](http://img.shields.io/gemnasium/hopsoft/tag_columns.svg?style=flat)](https://gemnasium.com/hopsoft/tag_columns)
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)
@@ -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,29 +20,46 @@ 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
36
33
  end
37
34
 
38
- scope :"with_#{method_name}", -> { where("#{quoted_column_name}::text[] IS NOT NULL").where("#{quoted_column_name}::text[] != '{}'") }
39
- scope :"without_#{method_name}", -> { where("#{quoted_column_name}::text[] IS NULL").or where("#{quoted_column_name}::text[] = '{}'") }
40
- scope :"with_any_#{method_name}", ->(*tags) { where "#{quoted_column_name}::text[] && ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
41
- scope :"with_all_#{method_name}", ->(*tags) { where "#{quoted_column_name}::text[] @> ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
42
- scope :"without_any_#{method_name}", ->(*tags) { where.not "#{quoted_column_name}::text[] && ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
43
- scope :"without_all_#{method_name}", ->(*tags) { where.not "#{quoted_column_name}::text[] @> ARRAY[?]::text[]", tag_columns_sanitize_list(tags) }
35
+ scope :"with_#{method_name}", -> {
36
+ where.not(arel_table[column_name].eq(nil)).where.not(arel_table[column_name].eq("{}"))
37
+ }
38
+
39
+ scope :"without_#{method_name}", -> {
40
+ where(arel_table[column_name].eq(nil)).or(where(arel_table[column_name].eq("{}")))
41
+ }
42
+
43
+ scope :"with_any_#{method_name}", ->(*tags) {
44
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
45
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
46
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
47
+ overlap = Arel::Nodes::InfixOperation.new("&&", column_cast, value_cast)
48
+ where overlap
49
+ }
44
50
 
45
- before_validation Proc.new { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
51
+ scope :"with_all_#{method_name}", ->(*tags) {
52
+ column_cast = Arel::Nodes::NamedFunction.new("CAST", [arel_table[column_name].as("text[]")])
53
+ value = Arel::Nodes::SqlLiteral.new(sanitize_sql_array(["ARRAY[?]", tag_columns_sanitize_list(tags)]))
54
+ value_cast = Arel::Nodes::NamedFunction.new("CAST", [value.as("text[]")])
55
+ contains = Arel::Nodes::InfixOperation.new("@>", column_cast, value_cast)
56
+ where contains
57
+ }
58
+
59
+ scope :"without_any_#{method_name}", ->(*tags) { where.not id: public_send(:"with_any_#{method_name}", *tags) }
60
+ scope :"without_all_#{method_name}", ->(*tags) { where.not id: public_send(:"with_all_#{method_name}", *tags) }
61
+
62
+ before_validation -> { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
46
63
 
47
64
  define_method :"has_any_#{method_name}?" do |*values|
48
65
  values = self.class.tag_columns_sanitize_list(values)
@@ -54,7 +71,7 @@ module TagColumns
54
71
  values = self.class.tag_columns_sanitize_list(values)
55
72
  existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
56
73
  (values & existing).size == values.size
57
- end
74
+ end
58
75
 
59
76
  alias_method :"has_#{method_name.singularize}?", :"has_all_#{method_name}?"
60
77
 
@@ -1,3 +1,3 @@
1
1
  module TagColumns
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubyforge_project:
106
- rubygems_version: 2.6.13
105
+ rubygems_version: 3.0.1
107
106
  signing_key:
108
107
  specification_version: 4
109
108
  summary: Fast & simple Rails ActiveRecord model tagging using PostgreSQL's Array datatype