Module: Card::Set::Type::SearchType

Extended by:
Card::Set
Included in:
Set
Defined in:
tmpsets/set/mod016-standard/type/search_type.rb

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

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

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from AdvancedApi

#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

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Card::Set::Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Instance Method Details

#count(params = {}) ⇒ Object



24
25
26
# File 'tmpsets/set/mod016-standard/type/search_type.rb', line 24

def count params={}
  Card.count_by_wql query(params)
end

#get_query(params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'tmpsets/set/mod016-standard/type/search_type.rb', line 33

def get_query params={}
  # why is this a wagn_bot thing?  can't deny search content??
  query = Auth.as_bot do
    query_content = params.delete(:query) || raw_content
    if query_content.empty?
      raise JSON::ParserError,
            "Error in card '#{name}':can't run search with empty content"
    elsif query_content.is_a?(String)
      JSON.parse(query_content)
    else query_content
    end
  end
  query.symbolize_keys!.merge! params.symbolize_keys
  if (default_limit = query.delete(:default_limit))
    query[:limit] ||= default_limit
  end
  query[:context] ||= cardname
  query
end

#item_cards(params = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'tmpsets/set/mod016-standard/type/search_type.rb', line 6

def item_cards params={}
  s = query(params)
  raise("OH NO.. no limit") unless s[:limit]
  # forces explicit limiting
  # can be 0 or less to force no limit
  Query.run(s, name)
end

#item_names(params = {}) ⇒ Object



14
15
16
17
# File 'tmpsets/set/mod016-standard/type/search_type.rb', line 14

def item_names params={}
  statement = query params.merge(return: :name)
  Query.run(statement, name)
end

#item_typeObject



19
20
21
22
# File 'tmpsets/set/mod016-standard/type/search_type.rb', line 19

def item_type
  return if query[:type].is_a?(Array) || query[:type].is_a?(Hash)
  query[:type]
end

#query(params = {}) ⇒ Object



28
29
30
31
# File 'tmpsets/set/mod016-standard/type/search_type.rb', line 28

def query params={}
  @query ||= {}
  @query[params.to_s] ||= get_query(params.clone)
end