Module: Card::Set::Abstract::WqlSearch
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod020-search/abstract/wql_search.rb
Overview
Set: Abstract (WqlSearch)
Defined Under Namespace
Modules: Format, HtmlFormat
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from I18nScope
#mod_name, #scope
Methods included from Loader
#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set
Methods included from Helpers
#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore
#attachment, #ensure_set, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
#include_set, #include_set_formats
Methods included from Basket
#abstract_basket, #add_to_basket, #basket, #unshift_basket
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
#event
Class Method Details
.source_location ⇒ Object
7
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 7
def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/search/set/abstract/wql_search.rb"; end
|
Instance Method Details
#cache_query? ⇒ Boolean
33
34
35
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 33
def cache_query?
true
end
|
#empty_query_error! ⇒ Object
79
80
81
82
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 79
def empty_query_error!
raise Error::BadQuery,
"Error in card '#{name}':can't run search with empty content"
end
|
#fetch_query(args = {}) ⇒ Object
37
38
39
40
41
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 37
def fetch_query args={}
@query = nil unless cache_query?
@query ||= {}
@query[args.to_s] ||= query(args.clone) end
|
#item_type ⇒ Object
84
85
86
87
88
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 84
def item_type
type = wql_hash[:type]
return if type.is_a?(Array) || type.is_a?(Hash)
type
end
|
#parse_json_query(query) ⇒ Object
72
73
74
75
76
77
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 72
def parse_json_query query
empty_query_error! if query.empty?
JSON.parse query
rescue
raise Error::BadQuery, "Invalid JSON search query: #{query}"
end
|
#query(args = {}) ⇒ Object
43
44
45
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 43
def query args={}
Query.new standardized_query_args(args), name
end
|
#query_args(args = {}) ⇒ Object
68
69
70
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 68
def query_args args={}
wql_hash.merge args
end
|
#search(args = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 10
def search args={}
with_skipping args do
query = fetch_query(args)
raise "OH NO.. no limit" unless query.mods[:limit]
query.run
end
end
|
#skip_search? ⇒ Boolean
for override, eg when required subqueries are known to be missing
21
22
23
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 21
def skip_search?
false
end
|
#skipped_search_result(args = {}) ⇒ Object
29
30
31
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 29
def skipped_search_result args={}
args[:return] == :count ? 0 : []
end
|
#standardized_query_args(args) ⇒ Object
47
48
49
50
51
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 47
def standardized_query_args args
args = query_args(args).symbolize_keys
args[:context] ||= name
args
end
|
#with_skipping(args) ⇒ Object
25
26
27
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 25
def with_skipping args
skip_search? ? skipped_search_result(args) : yield
end
|
#wql_from_content ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 59
def wql_from_content
@wql_from_content = nil unless cache_query?
@wql_from_content ||= begin
query = content
query = query.is_a?(Hash) ? query : parse_json_query(query)
query.symbolize_keys
end
end
|
#wql_hash ⇒ Object
override this to define search
54
55
56
57
|
# File 'tmpsets/set/mod020-search/abstract/wql_search.rb', line 54
def wql_hash
@wql_hash = nil unless cache_query?
@wql_hash ||= wql_from_content.merge filter_and_sort_wql
end
|