card-mod-lookup 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/card/{lookup_filter_query → lookup_query}/active_record_extension.rb +1 -1
- data/lib/card/{lookup_filter_query → lookup_query}/filtering.rb +13 -5
- data/lib/card/{lookup_filter_query.rb → lookup_query.rb} +2 -2
- data/set/abstract/lookup_search.rb +6 -10
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a98f8a016a2cab0a120e24080a6a9412c78df74364ffc335eeebcaed237d381e
|
4
|
+
data.tar.gz: ea21cc3f70eae3eabb38fcacd5bd69e6780c7fd9b365230536cb97c7ae211155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea4e3b72a7ff53aedb4045386d9d901c7b9b594f6faa44d534ef7add330c693a1e011ca942b3efa80997d903f5ab03a258d2461c569e61328bee40debff2da5
|
7
|
+
data.tar.gz: d10d164d42714b2db57d77101d69af7c74244402ec597018efc59ee06599edfd7b4cd2767fc11ebd1609590d6cf2bcd7bd9fb512d80ea82886502f8ccf6ef1a9
|
data/README.md
CHANGED
@@ -18,10 +18,10 @@ and when a database grows large, it can become quite expensive to execute all
|
|
18
18
|
the implied self joins.
|
19
19
|
|
20
20
|
For example, consider the use case that first inspired this code: _answers_ on
|
21
|
-
|
21
|
+
wikirate.org. Wikirate is a site that collects answers to questions about
|
22
22
|
companies. A given answer is a response to a given metric for a given year
|
23
23
|
for a given company. When you consider all the kinds of companies and metrics
|
24
|
-
and metric designers that
|
24
|
+
and metric designers that Wikirate supports, you can imagine the queries
|
25
25
|
becoming quite complex if we have to re-join the cards table to itself every
|
26
26
|
time we want to consider a different variable.
|
27
27
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Card
|
2
|
-
class
|
3
|
-
# shared filtering methods for
|
2
|
+
class LookupQuery
|
3
|
+
# shared filtering methods for query classes built on lookup tables
|
4
4
|
module Filtering
|
5
5
|
def process_filters
|
6
6
|
normalize_filter_args
|
@@ -17,7 +17,7 @@ class Card
|
|
17
17
|
if (method = filter_method key)
|
18
18
|
send method, key, value
|
19
19
|
else
|
20
|
-
try "#{key}
|
20
|
+
try "filter_by_#{key}", value
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -40,10 +40,13 @@ class Card
|
|
40
40
|
filter card_id_map[key], card_id
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
add_condition "#{lookup_class.card_column} not in (?)",
|
43
|
+
def filter_by_not_ids value
|
44
|
+
add_condition "#{lookup_class.card_column} not in (?)",
|
45
|
+
not_ids_value(value)
|
45
46
|
end
|
46
47
|
|
48
|
+
private
|
49
|
+
|
47
50
|
def to_card_id value
|
48
51
|
if value.is_a? Array
|
49
52
|
value.map(&:card_id)
|
@@ -106,6 +109,11 @@ class Card
|
|
106
109
|
def db_value value
|
107
110
|
value.is_a?(Array) ? "(?)" : "?"
|
108
111
|
end
|
112
|
+
|
113
|
+
def not_ids_value value
|
114
|
+
return value if value.is_a? Array
|
115
|
+
value.to_s.split ","
|
116
|
+
end
|
109
117
|
end
|
110
118
|
end
|
111
119
|
end
|
@@ -12,12 +12,12 @@ def run_query_returning query, return_type
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
raise Error::ServerError, "
|
15
|
+
def query_class
|
16
|
+
raise Error::ServerError, "query_class required!"
|
17
17
|
end
|
18
18
|
|
19
19
|
def query paging={}
|
20
|
-
|
20
|
+
query_class.new query_hash, {}, paging
|
21
21
|
end
|
22
22
|
|
23
23
|
def query_hash
|
@@ -29,7 +29,7 @@ def count
|
|
29
29
|
end
|
30
30
|
|
31
31
|
format do
|
32
|
-
delegate :
|
32
|
+
delegate :query_class, to: :card
|
33
33
|
|
34
34
|
def search_with_params
|
35
35
|
@search_with_params ||= card.search query: query
|
@@ -40,11 +40,11 @@ format do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def query
|
43
|
-
|
43
|
+
query_class.new query_hash, sort_hash, paging_params
|
44
44
|
end
|
45
45
|
|
46
46
|
def count_query
|
47
|
-
|
47
|
+
query_class.new query_hash
|
48
48
|
end
|
49
49
|
|
50
50
|
def query_hash
|
@@ -89,10 +89,6 @@ format do
|
|
89
89
|
safe_sql_param(:sort_by)&.to_sym || safe_sql_param(:sort)&.to_sym
|
90
90
|
end
|
91
91
|
|
92
|
-
def default_limit
|
93
|
-
Auth.signed_in? ? 5000 : 500
|
94
|
-
end
|
95
|
-
|
96
92
|
# not a CQL search
|
97
93
|
def filter_cql
|
98
94
|
{}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Kühl
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: card
|
@@ -47,9 +47,9 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- README.md
|
50
|
-
- lib/card/
|
51
|
-
- lib/card/
|
52
|
-
- lib/card/
|
50
|
+
- lib/card/lookup_query.rb
|
51
|
+
- lib/card/lookup_query/active_record_extension.rb
|
52
|
+
- lib/card/lookup_query/filtering.rb
|
53
53
|
- lib/lookup_table.rb
|
54
54
|
- lib/lookup_table/class_methods.rb
|
55
55
|
- set/abstract/lookup.rb
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.4.10
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: lookup
|