Module: Card::Set::Abstract::CqlSearch
- Extended by:
- Card::Set
- Defined in:
- platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb
Overview
Set: Abstract (CqlSearch)
Defined Under Namespace
Modules: Format, HtmlFormat
Constant Summary
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Constants included from Event::Api
Class Method Summary collapse
Instance Method Summary collapse
-
#cache_query? ⇒ Boolean
-
#cql_content ⇒ Object
override this to define search.
-
#cql_hash ⇒ Object
-
#empty_query_error! ⇒ Object
-
#fetch_query(args = {}) ⇒ Object
-
#item_type_id ⇒ Object
-
#parse_json_cql(query) ⇒ Object
-
#query(args = {}) ⇒ Object
-
#search(args = {}) ⇒ Object
These search methods are shared by card and format.
-
#skip_search? ⇒ Boolean
for override, eg when required subqueries are known to be missing.
-
#with_skipping(args) ⇒ Object
Methods included from Card::Set
Methods included from I18nScope
Methods included from Registrar
#extended, #finalize_load, #process_base_modules, #register_set
Methods included from Helpers
#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name
Methods included from Card::Set::AdvancedApi
#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Class Method Details
.source_location ⇒ Object
7 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/mod/search/set/abstract/cql_search.rb"; end |
Instance Method Details
#cache_query? ⇒ Boolean
32 33 34 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 32 def cache_query? true end |
#cql_content ⇒ Object
override this to define search
15 16 17 18 19 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 15 def cql_content query = content query = query.is_a?(Hash) ? query : parse_json_cql(query) query.symbolize_keys end |
#cql_hash ⇒ Object
10 11 12 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 10 def cql_hash cache_query? ? (@cql_hash ||= cql_content) : cql_content end |
#empty_query_error! ⇒ Object
43 44 45 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 43 def empty_query_error! raise Error::BadQuery, "can't run search with empty content" end |
#fetch_query(args = {}) ⇒ Object
65 66 67 68 69 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 65 def fetch_query args={} @query = nil unless cache_query? @query ||= {} @query[args.to_s] ||= query(args.clone) # cache query end |
#item_type_id ⇒ Object
21 22 23 24 25 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 21 def item_type_id type = cql_hash[:type] type = type&.card_id if plausible_type? type type if type.is_a? Integer end |
#parse_json_cql(query) ⇒ Object
36 37 38 39 40 41 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 36 def parse_json_cql query empty_query_error! if query.empty? JSON.parse query rescue JSON::ParserError raise Error::BadQuery, "Invalid JSON search query: #{query}" end |
#query(args = {}) ⇒ Object
71 72 73 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 71 def query args={} Query.new standardized_query_args(args), name end |
#search(args = {}) ⇒ Object
These search methods are shared by card and format
48 49 50 51 52 53 54 55 56 57 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 48 def search args={} with_skipping args do query = fetch_query(args) # forces explicit limiting # can be 0 or less to force no limit 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
28 29 30 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 28 def skip_search? false end |
#with_skipping(args) ⇒ Object
59 60 61 62 63 |
# File 'platypus/tmp/set/gem-defaults/mod009-search/abstract/cql_search.rb', line 59 def with_skipping args return yield unless skip_search? args[:return] == :count ? 0 : [] end |