tag_columns 0.1.0 → 0.1.1
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/lib/tag_columns/version.rb +1 -1
- data/lib/tag_columns.rb +10 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70fdfc0271ea3299c00a03617d8ac8ab3c1aa922
|
4
|
+
data.tar.gz: 59f0c97926eb432b77ee06449d0c8ae185bc7af9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6c2a2898846a98c5aa13356866d1cddd709d0a2025799bd3166bcedbdd0c2b92b46756bf4855e22a9a5c040c486fc34d4f25b6c4a212b9e0caef9caca102159
|
7
|
+
data.tar.gz: 2474138516e22364189e4a84339ff80226391ca44be868904a00e6ddb3c03cf28676a7ebfb575761ea76238a79b183c974ae9e76dfec03a4823f6a91de7e7f8c
|
data/Gemfile.lock
CHANGED
data/lib/tag_columns/version.rb
CHANGED
data/lib/tag_columns.rb
CHANGED
@@ -20,27 +20,27 @@ module TagColumns
|
|
20
20
|
@tag_columns.each do |column_name, initialized|
|
21
21
|
next if initialized
|
22
22
|
|
23
|
-
|
23
|
+
method_name = column_name.downcase
|
24
24
|
quoted_column_name = "#{quoted_table_name}.#{connection.quote_column_name column_name}"
|
25
25
|
|
26
|
-
scope :"with_any_#{
|
27
|
-
scope :"with_all_#{
|
28
|
-
scope :"without_any_#{
|
29
|
-
scope :"without_all_#{
|
26
|
+
scope :"with_any_#{method_name}", ->(*tags) { where "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
27
|
+
scope :"with_all_#{method_name}", ->(*tags) { where "#{quoted_column_name} @> ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
28
|
+
scope :"without_any_#{method_name}", ->(*tags) { where.not "#{quoted_column_name} && ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
29
|
+
scope :"without_all_#{method_name}", ->(*tags) { where.not "#{quoted_column_name} @> ARRAY[?]::varchar[]", tag_columns_sanitize_list(tags) }
|
30
30
|
|
31
31
|
before_validation Proc.new { self[column_name] = self.class.tag_columns_sanitize_list(self[column_name]) }
|
32
32
|
|
33
|
-
define_method :"has_any_#{
|
33
|
+
define_method :"has_any_#{method_name}?" do |*values|
|
34
34
|
values = self.class.tag_columns_sanitize_list(values)
|
35
|
-
existing = self[column_name] || []
|
35
|
+
existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
|
36
36
|
(values & existing).present?
|
37
37
|
end
|
38
38
|
|
39
|
-
alias_method :"has_#{
|
39
|
+
alias_method :"has_#{method_name.singularize}?", :"has_any_#{method_name}?"
|
40
40
|
|
41
|
-
define_method :"has_all_#{
|
41
|
+
define_method :"has_all_#{method_name}?" do |*values|
|
42
42
|
values = self.class.tag_columns_sanitize_list(values)
|
43
|
-
existing = self[column_name] || []
|
43
|
+
existing = self.class.tag_columns_sanitize_list(self[column_name] || [])
|
44
44
|
(values & existing).size == values.size
|
45
45
|
end
|
46
46
|
|