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

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

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #pattern_and_modules_from_path, #process_base_modules, #register_set, #tmp_file_frame, #tmp_file_template, #tmp_file_wrapped_content, #write_tmp_file

Methods included from Helpers

#abstract_set?, #all_set?, #shortname

Methods included from AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#all_set_format_mod!, #define_on_format, #format, #register_set_format, #view

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket

Methods included from Card::Set::Trait

#card_accessor, #card_reader, #card_writer

Methods included from Event

#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